{"record":{"id":"5c3060c0202f49c4","repo":"different-ai/openwork","slug":"failed-to-load-api-keys-response-status","errorCode":null,"errorMessage":"Failed to load API keys (${response.status}).","messagePattern":"Failed to load API keys \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/api-keys-screen.tsx","lineNumber":97,"sourceCode":"        if (!orgId || !access.canViewSettings) {\n            if (isCurrent()) {\n                setApiKeys([]);\n            }\n            return;\n        }\n\n        if (isCurrent()) {\n            setBusy(true);\n            setError(null);\n        }\n        try {\n            const { response, payload } = await requestJson(\n                `/v1/api-keys`,\n                { method: \"GET\" },\n                12000,\n            );\n            if (!response.ok) {\n                throw getRequestError(payload, response, `Failed to load API keys (${response.status}).`);\n            }\n\n            if (isCurrent()) {\n                setApiKeys(parseOrgApiKeysPayload(payload));\n            }\n        } catch (nextError) {\n            if (isReauthRequiredError(nextError)) {\n                throw nextError;\n            }\n\n            if (isCurrent()) {\n                setError(\n                    nextError instanceof Error\n                        ? nextError.message\n                        : \"Failed to load API keys.\",\n                );\n            }\n        } finally {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/api-keys-screen.tsx#L79-L115","documentation":"loadApiKeys in the Den dashboard fetches GET /v1/api-keys via requestJson and, when the HTTP response is not ok, throws getRequestError(payload, response, 'Failed to load API keys (<status>)'). The generic message is enriched with any error detail the server returned in the payload. It surfaces auth/session problems and server faults from the Den control plane.","triggerScenarios":"GET /v1/api-keys returns any non-ok status: 401/403 (expired or missing Den session, wrong org), 404 (wrong base URL/gateway), 5xx (Den server error), or 429 (rate limited); the request itself has a 12s timeout handled separately.","commonSituations":"Session token expired after idle; user switched orgs without refreshing the session; API base URL misconfigured in the Den web deployment; Den backend outage; load balancer returning 502/503.","solutions":["Read response.status and the server payload detail to identify the exact cause (401/403 vs 5xx).","For 401/403, re-authenticate the Den session (sign in again) and retry.","Verify the Den API base URL / deployment routing is correct for the current org.","For 5xx/429, retry with backoff; check Den server health/logs if it persists."],"exampleFix":"// before\ntry { await loadApiKeys(); } catch (e) { setError(String(e)); }\n// after\ntry {\n  await loadApiKeys();\n} catch (e) {\n  if (e.status === 401 || e.status === 403) { redirectToSignIn(); return; }\n  setError(`Could not load API keys (${e.status ?? \"network\"}). Retry or contact your Den admin.`);\n}","handlingStrategy":"try-catch","validationCode":"if (!session?.token) throw new Error(\"Sign in to Den before loading API keys\");","typeGuard":"function hasActiveSession(s) {\n  return Boolean(s && typeof s.token === \"string\" && s.token.length > 0 && (!s.expiresAt || Date.now() < s.expiresAt));\n}","tryCatchPattern":"try {\n  await loadApiKeys();\n} catch (e) {\n  const status = e.status ?? Number(/\\((\\d{3})\\)/.exec(e.message)?.[1]);\n  if (status === 401 || status === 403) redirectToSignIn();\n  else if (status >= 500 || status === 429) scheduleRetryLoad();\n  else setError(e.message);\n}","preventionTips":["Check session validity (token present, not expired) before dashboard data loads.","Handle 401/403 with a redirect to sign-in rather than a generic error toast.","Retry 5xx/429 with backoff; alert on sustained Den server failures.","Verify the Den API base URL in deployment config on 404s."],"tags":["den","api","http","authentication"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}