{"record":{"id":"47887aa979687f64","repo":"different-ai/openwork","slug":"failed-to-load-desktop-policies-response-status","errorCode":null,"errorMessage":"Failed to load desktop policies (${response.status}).","messagePattern":"Failed to load desktop policies \\((.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx","lineNumber":174,"sourceCode":"export function useOrgDesktopPolicies(orgId: string | null) {\n  const [definitions, setDefinitions] = useState<DesktopPolicyDefinition[]>([]);\n  const [desktopPolicies, setDesktopPolicies] = useState<DenDesktopPolicy[]>([]);\n  const [busy, setBusy] = useState(false);\n  const [error, setError] = useState<string | null>(null);\n\n  async function reloadPolicies() {\n    if (!orgId) {\n      setDefinitions([]);\n      setDesktopPolicies([]);\n      return;\n    }\n\n    setBusy(true);\n    setError(null);\n    try {\n      const { response, payload } = await requestJson(\"/v1/desktop-policies\", { method: \"GET\" }, 12000);\n      if (!response.ok) {\n        throw new Error(getErrorMessage(payload, `Failed to load desktop policies (${response.status}).`));\n      }\n      const parsed = parseDesktopPolicyList(payload);\n      setDefinitions(parsed.definitions);\n      setDesktopPolicies(parsed.desktopPolicies);\n    } catch (error) {\n      setError(error instanceof Error ? error.message : \"Failed to load desktop policies.\");\n    } finally {\n      setBusy(false);\n    }\n  }\n\n  useEffect(() => {\n    void reloadPolicies();\n  }, [orgId]);\n\n  return { definitions, desktopPolicies, busy, error, reloadPolicies };\n}\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx#L156-L192","documentation":"reloadPolicies fetches GET /v1/desktop-policies through requestJson with a 12s timeout. If the Den server responds with a non-OK status, getErrorMessage(payload, fallback) is used: the fallback string `Failed to load desktop policies (${response.status})` surfaces unless the JSON payload carries a more specific message. The caught error is stored in component state via setError, so the message is displayed in the desktop policies screen.","triggerScenarios":"GET /v1/desktop-policies returns 401/403 (not signed in or not an org admin), 402 (plan gating on the list endpoint), 404 (server version without the endpoint), 5xx (Den backend failure), or requestJson throws its own timeout/abort error which is caught and replaced by the generic \"Failed to load desktop policies.\" message.","commonSituations":"Session token expired while the dashboard stayed open; user lacks admin role in the org; self-hosted Den server is an older version without /v1/desktop-policies; Den backend momentarily down; slow network exceeding the 12s timeout.","solutions":["Check the HTTP status in the message and the Den server logs for the matching request; fix the underlying API failure (auth, permissions, or backend).","Re-authenticate: sign out and back in to refresh the Den session, then reload the dashboard.","Verify the account has org admin rights required to read desktop policies.","If the status is 404, upgrade the self-hosted Den server to a version that implements /v1/desktop-policies.","For timeouts, check connectivity to the Den instance and retry."],"exampleFix":"// before (server returns 403, user is member not admin)\nawait reloadPolicies(); // -> \"Failed to load desktop policies (403).\"\n\n// after: grant the user the org admin role in Den, then\nawait reloadPolicies(); // loads definitions + desktopPolicies","handlingStrategy":"try-catch","validationCode":"if (!denSessionActive()) redirectToSignIn(); // avoid predictable 401s before reloadPolicies()","typeGuard":"function isHttpError(e: unknown): e is Error & { status?: number } {\n  return e instanceof Error && /\\(\\d{3}\\)/.test(e.message);\n}","tryCatchPattern":"try {\n  await reloadPolicies();\n} catch (e) {\n  if (isHttpError(e) && e.message.includes(\"401\")) {\n    promptReSignIn();\n  } else {\n    showError(e instanceof Error ? e.message : \"Failed to load desktop policies.\");\n  }\n}","preventionTips":["Refresh the Den session token proactively before long-lived dashboard data loads.","Gate the desktop policies UI behind an admin-role check so non-admins never hit the endpoint.","Log response status + payload server-side to correlate UI errors with backend failures.","Add a retry with backoff for transient 5xx/timeouts on the 12s requestJson call."],"tags":["network","http","api","react"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}