{"record":{"id":"afd04bc5d84485ab","repo":"different-ai/openwork","slug":"failed-to-delete-desktop-policy-response-status","errorCode":null,"errorMessage":"Failed to delete desktop policy (${response.status}).","messagePattern":"Failed to delete desktop policy \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx","lineNumber":222,"sourceCode":"\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":204,"sourceCodeEnd":225,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx#L204-L225","documentation":"Thrown by deleteDesktopPolicy when DELETE /v1/desktop-policies/:id returns non-OK. Unlike its create/update siblings there is no 402 special case: getRequestError either throws ReauthRequiredError (403 reauth payload) or an Error with the server message or this fallback. It means the server refused to delete the policy.","triggerScenarios":"DELETE /v1/desktop-policies/{policyId} fails: policy already deleted (404), protected/default policy that cannot be removed (400/409), insufficient permissions (401/403), or 5xx. 12s timeout. Called from softDeletePolicy.","commonSituations":"Double-clicking delete (second call 404s); trying to delete the default policy; non-admin session; stale UI after another admin already removed the policy.","solutions":["If 404, refresh the policy list - the policy is already gone.","Check whether the policy is default/protected and disable instead of delete.","Re-authenticate on reauth/session errors and retry.","Retry as an org admin with policy permissions.","Inspect server logs for 5xx."],"exampleFix":"// before\nif (!response.ok) {\n  throw getRequestError(payload, response, `Failed to delete desktop policy (${response.status}).`);\n}\n// after\nif (!response.ok) {\n  if (response.status === 404) return; // already deleted, treat as success\n  throw getRequestError(payload, response, `Failed to delete desktop policy (${response.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"const policy = policies.find((p) => p.id === policyId);\nif (!policy) { refreshPolicies(); return; } // already gone\nif (policy.isDefault) { showToast(\"The default policy cannot be deleted.\"); return; }","typeGuard":"function isNotFound(error: unknown): boolean { return error instanceof Error && error.message.includes(\"404\"); }","tryCatchPattern":"try {\n  await deleteDesktopPolicy(policyId);\n} catch (error) {\n  if (isNotFound(error)) { refreshPolicies(); return; } // idempotent delete\n  if (isReauthRequiredError(error)) { promptReauth(); return; }\n  showToast(error.message);\n}","preventionTips":["Treat 404 as success (delete is idempotent) and refresh the list","Prevent deleting default/protected policies in the UI","Disable the delete button for non-admins","Debounce double-clicks on the delete action"],"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"}