{"record":{"id":"6f5aa92b67ec1651","repo":"different-ai/openwork","slug":"failed-to-load-organization-response-status","errorCode":null,"errorMessage":"Failed to load organization (${response.status}).","messagePattern":"Failed to load organization \\((.+?)\\)\\.","errorType":"http","errorClass":"OrganizationNotFoundError","httpStatus":404,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx","lineNumber":183,"sourceCode":"      },\n      12000,\n    );\n\n    if (!response.ok) {\n      throw new Error(getErrorMessage(payload, `Failed to switch organization (${response.status}).`));\n    }\n  }\n\n  async function loadOrgContext(organizationId: string, refreshRoles: boolean) {\n    const path = refreshRoles ? \"/v1/org?refreshRoles=true\" : \"/v1/org\";\n    const { response, payload } = await requestJson(\n      path,\n      { method: \"GET\", headers: { [ORG_SCOPE_HEADER]: organizationId } },\n      12000,\n    );\n    if (!response.ok) {\n      if (response.status === 404) {\n        throw new OrganizationNotFoundError(getErrorMessage(payload, `Failed to load organization (${response.status}).`));\n      }\n\n      throw new Error(getErrorMessage(payload, `Failed to load organization (${response.status}).`));\n    }\n\n    const parsed = parseOrgContextPayload(payload);\n    if (!parsed) {\n      throw new Error(\"Organization context response was incomplete.\");\n    }\n\n    return parsed;\n  }\n\n  async function restoreDisplayedOrganization() {\n    const displayedOrgId = orgContext?.organization.id;\n    if (!displayedOrgId) {\n      return;\n    }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx#L165-L201","documentation":"loadOrgContext GETs /v1/org with the ORG_SCOPE_HEADER set to the organizationId and throws this plain Error for any non-ok status except 404 (404 throws OrganizationNotFoundError instead — see error 1113's sibling branch). It means the org-scoped context (settings, roles) could not be fetched for the active organization.","triggerScenarios":"GET /v1/org returns 401 (expired session), 403 (user lost access / role revoked for this org), 500/503 (server error), or 400 (invalid ORG_SCOPE_HEADER value) — anything other than 404.","commonSituations":"User's admin revoked their membership mid-session; Den server returning 5xx during deploy or DB migration; client sending a malformed org id header after bad state restore.","solutions":["Check the interpolated status: 403 → confirm membership server-side and prompt the user to switch organizations.","401 → re-authenticate (sign-in flow) before retrying the context load.","Inspect the ORG_SCOPE_HEADER value being sent; a null/undefined id produces 400s — restore from the org list instead.","For 5xx, check den-api logs and retry with backoff; context loads are read-only so retries are safe.","Wrap the context loader in the UI's org error boundary and offer refreshOrgData as recovery."],"exampleFix":"// before\nconst parsed = await loadOrgContext(orgId, false); // throws generic error on 403\n// after\ntry {\n  const parsed = await loadOrgContext(orgId, false);\n} catch (err) {\n  if (err instanceof OrganizationNotFoundError || String(err).includes(\"403\")) {\n    await refreshOrgData(); // drop inaccessible org, select another\n  } else throw err;\n}","handlingStrategy":"try-catch","validationCode":"if (!organizationId) { await refreshOrgData(); return; } // don't call with a blank scope header","typeGuard":"function hasOrgScope(o: unknown): o is { organizationId: string } {\n  return typeof o === \"object\" && o !== null && typeof (o as { organizationId?: unknown }).organizationId === \"string\" && o.organizationId.length > 0;\n}","tryCatchPattern":"try {\n  await loadOrgContext(orgId, false);\n} catch (err) {\n  if (err instanceof OrganizationNotFoundError || String(err.message).includes(\"403\")) {\n    await refreshOrgData();\n  } else {\n    throw err;\n  }\n}","preventionTips":["Always source the org id from the directory response, never from local edits.","Treat 401/403 as re-auth/membership issues, not retryable ones.","Retry only 5xx, with backoff.","Watch for role revocations mid-session and offer a re-sync action.","Send ORG_SCOPE_HEADER only with validated, non-empty ids."],"tags":["http","api","org-context","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"}