{"record":{"id":"7a2cf818bf30bdb9","repo":"different-ai/openwork","slug":"failed-to-update-desktop-policy-response-status","errorCode":null,"errorMessage":"Failed to update desktop policy (${response.status}).","messagePattern":"Failed to update desktop policy \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx","lineNumber":213,"sourceCode":"    method: \"POST\",\n    headers: { \"content-type\": \"application/json\" },\n    body: JSON.stringify(input),\n  }, 12000);\n  if (!response.ok) {\n    if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\n    throw getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);\n  }\n}\n\nexport async function updateDesktopPolicy(policyId: string, input: DesktopPolicyPayload) {\n  const { response, payload } = await requestJson(`/v1/desktop-policies/${encodeURIComponent(policyId)}`, {\n    method: \"PATCH\",\n    headers: { \"content-type\": \"application/json\" },\n    body: JSON.stringify(input),\n  }, 12000);\n  if (!response.ok) {\n    if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\n    throw getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);\n  }\n}\n\nexport async function deleteDesktopPolicy(policyId: string) {\n  const { response, payload } = await requestJson(`/v1/desktop-policies/${encodeURIComponent(policyId)}`, {\n    method: \"DELETE\",\n  }, 12000);\n  if (!response.ok) {\n    throw getRequestError(payload, response, `Failed to delete desktop policy (${response.status}).`);\n  }\n}\n","sourceCodeStart":195,"sourceCodeEnd":225,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx#L195-L225","documentation":"Thrown by updateDesktopPolicy when PATCH /v1/desktop-policies/:id returns non-OK. 402 maps to the enterprise-plan error; otherwise the server message or this status fallback is thrown. It means an existing desktop policy could not be modified.","triggerScenarios":"PATCH /v1/desktop-policies/{policyId} fails: org lacks enterprise plan (402), invalid payload (400/422), unknown policyId (404), missing permissions (401/403), or 5xx. Called from handleSave, handleToggleEnabled, updateDefaultPolicy, updateAdminExceptionPolicy, disablePolicy.","commonSituations":"Toggling a policy's enabled flag on a non-enterprise org; policy deleted in another tab (404); edited rule values failing validation; expired admin session.","solutions":["If 402/enterprise-plan message: upgrade the org plan or stop editing policies.","Refresh the policy list to confirm the policy still exists (404).","Validate the payload fields before PATCHing.","Re-authenticate on reauth-required errors and retry the toggle/save.","Check server logs on 5xx."],"exampleFix":"// before\nif (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\nthrow getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);\n// after\nif (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\nif (response.status === 404) throw new Error(\"This policy no longer exists - refresh the list.\");\nthrow getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);","handlingStrategy":"try-catch","validationCode":"const exists = policies.some((p) => p.id === policyId);\nif (!exists) { refreshPolicies(); return; } // avoid 404 on stale row","typeGuard":"function isEnterprisePlanError(e: unknown): boolean { return e instanceof Error && e.message === DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR; }","tryCatchPattern":"try {\n  await updateDesktopPolicy(policyId, input);\n} catch (error) {\n  if (isEnterprisePlanError(error)) { showUpgradePrompt(); return; }\n  if (error instanceof Error && /404/.test(error.message)) { refreshPolicies(); return; }\n  showToast(error.message);\n}","preventionTips":["Re-fetch policies before toggling to avoid stale 404s","Gate editing behind enterprise-plan checks to preempt 402","Use optimistic updates with rollback so a failed toggle reverts the switch","Catch reauth errors via isReauthRequiredError and retry"],"tags":["http","policy","permissions","network"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}