{"record":{"id":"72459ff130c89034","repo":"different-ai/openwork","slug":"failed-to-create-desktop-policy-response-status","errorCode":null,"errorMessage":"Failed to create desktop policy (${response.status}).","messagePattern":"Failed to create desktop policy \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx","lineNumber":201,"sourceCode":"    }\n  }\n\n  useEffect(() => {\n    void reloadPolicies();\n  }, [orgId]);\n\n  return { definitions, desktopPolicies, busy, error, reloadPolicies };\n}\n\nexport async function createDesktopPolicy(input: DesktopPolicyPayload) {\n  const { response, payload } = await requestJson(\"/v1/desktop-policies\", {\n    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\",","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx#L183-L219","documentation":"Thrown by createDesktopPolicy when POST /v1/desktop-policies returns non-OK. Status 402 is special-cased into the DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR (enterprise plan required); otherwise getRequestError throws the server message or this fallback. It means the server rejected creating the desktop policy.","triggerScenarios":"POST /v1/desktop-policies fails: org not on an enterprise plan (402), validation failure in the policy payload (400/422), insufficient permissions (401/403), or server error (5xx). 12s timeout.","commonSituations":"Free/standard org attempting policy management (402); policy JSON with invalid rules failing server validation; admin session expired; also hit indirectly by ensureAdminExceptionPolicy auto-creating the admin exception policy.","solutions":["Upgrade the org to an enterprise plan if the error is the 402 enterprise-plan message.","Validate the DesktopPolicyPayload shape client-side before POSTing to pass server validation.","Re-authenticate if the error indicates an expired/reauth-needed session.","Retry as a user with policy-management permissions.","For 5xx, check Den server logs."],"exampleFix":"// before\nif (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\nthrow getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);\n// after\nif (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);\nif (response.status === 400) throw new Error(getErrorMessage(payload, \"Invalid policy settings - check the form values.\"));\nthrow getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);","handlingStrategy":"try-catch","validationCode":"function policyPayloadOk(p: DesktopPolicyPayload): boolean {\n  return typeof p.name === \"string\" && p.name.trim().length > 0; // + rule schema checks\n}\nif (!policyPayloadOk(input)) throw new Error(\"Invalid policy payload\");","typeGuard":"function isEnterprisePlanError(e: unknown): boolean { return e instanceof Error && e.message === DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR; }","tryCatchPattern":"try {\n  await createDesktopPolicy(input);\n} catch (error) {\n  if (isEnterprisePlanError(error)) { showUpgradePrompt(); return; }\n  if (isReauthRequiredError(error)) { promptReauth(); return; }\n  showToast(error.message);\n}","preventionTips":["Gate the policies UI behind enterprise-plan detection (GET org/plan) to avoid 402","Validate the policy form against the server schema before submit","Refresh the policy list before creating to detect permission/state issues","Handle ensureAdminExceptionPolicy failures separately from user-initiated saves"],"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"}