{"record":{"id":"bc689d2bc2bb6c99","repo":"different-ai/openwork","slug":"failed-to-load-organizations-response-status","errorCode":null,"errorMessage":"Failed to load organizations (${response.status}).","messagePattern":"Failed to load organizations \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx","lineNumber":153,"sourceCode":"  }\n\n  function ensureTargetIsNotOwner(memberId: string) {\n    const target = orgContext?.members.find((member) => member.id === memberId) ?? null;\n    if (target?.isOwner) {\n      throw new Error(\"The workspace owner cannot be changed or removed from this action.\");\n    }\n    return target;\n  }\n\n  function shouldRefreshRolesForPage(org: DenOrgSummary) {\n    const isMembersPage = pathname === \"/dashboard/members\" || pathname === \"/dashboard/manage-members\";\n    return isMembersPage && getOrgAccessFlags(org.role, false).isAdmin;\n  }\n\n  async function loadOrgDirectory() {\n    const { response, payload } = await requestJson(\"/v1/me/orgs\", { method: \"GET\" }, 12000);\n    if (!response.ok) {\n      throw new Error(getErrorMessage(payload, `Failed to load organizations (${response.status}).`));\n    }\n\n    return parseOrgListPayload(payload);\n  }\n\n  async function setActiveOrganization(input: { organizationId?: string | null; organizationSlug?: string | null }) {\n    const { response, payload } = await requestJson(\n      \"/api/auth/organization/set-active\",\n      {\n        method: \"POST\",\n        body: JSON.stringify(input),\n      },\n      12000,\n    );\n\n    if (!response.ok) {\n      throw new Error(getErrorMessage(payload, `Failed to switch organization (${response.status}).`));\n    }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx#L135-L171","documentation":"loadOrgDirectory fetches GET /v1/me/orgs (12s timeout) and throws this error whenever the HTTP response is not ok. The message interpolates the HTTP status; a server-provided error message (via getErrorMessage) takes precedence when present. It signals the dashboard could not retrieve the user's organization list, so the org directory payload cannot be built.","triggerScenarios":"GET /v1/me/orgs returns 401/403 (expired or missing session cookie), 404/410 (route removed or version mismatch), 500/502/503 (server or upstream failure), or a network-level failure resolved by requestJson's timeout as a non-ok response.","commonSituations":"Users with stale Den sessions after server restart or token rotation; self-hosted deployments behind a proxy stripping auth cookies; API version drift between den-web and the den-api server causing 404s.","solutions":["Check the interpolated status in the message: 401/403 → re-authenticate (sign in again to refresh the Den session cookie).","Call the endpoint directly (curl -i /v1/me/orgs with the session cookie) to see the raw body and confirm the server-side error detail.","Verify den-web's API base URL / reverse-proxy routes point at a den-api version that still serves /v1/me/orgs.","For 5xx, inspect den-api server logs for the corresponding request; fix upstream DB/upstream dependency and retry.","If the network is flaky, add a retry/backoff wrapper around refreshOrgData since requestJson enforces a hard 12s timeout."],"exampleFix":"// before\nconst { response, payload } = await requestJson(\"/v1/me/orgs\", { method: \"GET\" }, 12000);\nif (!response.ok) {\n  throw new Error(getErrorMessage(payload, `Failed to load organizations (${response.status}).`));\n}\n// after\nconst { response, payload } = await requestJson(\"/v1/me/orgs\", { method: \"GET\" }, 12000);\nif (response.status === 401) {\n  await reauthenticate(); // refresh session then retry once\n  return loadOrgDirectory();\n}\nif (!response.ok) {\n  throw new Error(getErrorMessage(payload, `Failed to load organizations (${response.status}).`));\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight: ensure a session exists\nconst sessionOk = document.cookie.includes(\"den_session\") ?? await checkSession();\nif (!sessionOk) await signIn();","typeGuard":"function isOrgListPayload(p: unknown): p is { organizations: { slug: string; role: string }[] } {\n  return typeof p === \"object\" && p !== null && Array.isArray((p as { organizations?: unknown }).organizations);\n}","tryCatchPattern":"try {\n  await refreshOrgData();\n} catch (err) {\n  if (String(err.message).includes(\"401\")) redirectToSignIn();\n  else if (String(err.message).includes(\"404\")) showApiVersionError();\n  else showRetryableError(err, () => refreshOrgData());\n}","preventionTips":["Keep sessions alive; re-authenticate before long dashboard sessions.","Pin den-web and den-api versions so /v1/me/orgs never disappears underneath the client.","Add retry with backoff for 5xx on dashboard load.","Monitor the interpolated status codes in this message for auth vs server trends.","Test behind your production reverse proxy so stripped cookies surface in CI."],"tags":["http","network","api","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"}