{"record":{"id":"ef84d28999ce683d","repo":"different-ai/openwork","slug":"failed-to-load-library-response-status","errorCode":null,"errorMessage":"Failed to load library (${response.status}).","messagePattern":"Failed to load library \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/library-data.tsx","lineNumber":284,"sourceCode":"    .filter((item): item is LibraryItem => item !== null);\n  const supportedItemCount = payload.items.filter((item) => !isRecord(item) || item.type !== \"app\").length;\n  if (items.length !== supportedItemCount) {\n    throw new Error(\"Library response was incomplete.\");\n  }\n  return items;\n}\n\nexport function useLibrary() {\n  return useQuery({\n    queryKey: libraryQueryKeys.items,\n    queryFn: async (): Promise<LibraryItem[]> => {\n      const { response, payload } = await requestJson(\n        \"/v1/me/library\",\n        { method: \"GET\" },\n        15000,\n      );\n      if (!response.ok) {\n        throw new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));\n      }\n      return parseLibraryPayload(payload);\n    },\n  });\n}\n","sourceCodeStart":266,"sourceCodeEnd":290,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/library-data.tsx#L266-L290","documentation":"useLibrary's query function calls GET /v1/me/library via requestJson; when the HTTP response is not ok it throws an Error whose message prefers a server-provided message (getErrorMessage) and otherwise embeds the HTTP status. This surfaces transport-level failures (auth, server error, not found) to React Query's error state.","triggerScenarios":"GET /v1/me/library responds with 401 (expired/missing session), 403 (no org access), 404 (route missing/old server), 429, or 5xx (backend failure); network-layer completion with non-2xx status.","commonSituations":"Session token expired while the dashboard is open; user lacks the organization that owns the library; deployed web frontend points at a server without this route; backend outage or rate limiting.","solutions":["Check response.status in the error and the server message from getErrorMessage to identify 401/403/404/5xx.","For 401, re-authenticate the user (refresh session or redirect to sign-in).","For 404, confirm the frontend talks to a server version that implements /v1/me/library.","For 5xx, check den-api server logs and retry once the backend recovers.","Confirm the request includes the correct org/auth headers expected by the endpoint."],"exampleFix":"// before\nthrow new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));\n// after (distinguish auth failures for redirect handling)\nif (response.status === 401) throw new LibraryAuthError(getErrorMessage(payload, \"Sign in required.\"));\nthrow new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const { isLoading, data, error } = useLibrary();\nif (error) {\n  const m = error instanceof Error ? error.message : String(error);\n  if (/\\(401\\)/.test(m)) redirectToSignIn();\n  else showRetryBanner(`Library unavailable: ${m}`);\n}","preventionTips":["Handle 401 globally with session refresh before queries fire.","Version-check the den-api server at app startup to catch missing routes early.","Render per-query error states instead of letting queries throw unhandled.","Monitor 4xx/5xx rates on /v1/me/library in server metrics."],"tags":["network","http-status","react-query","den-web"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}