different-ai/openwork · error · Error

Failed to create desktop policy

Error message

Failed to create desktop policy (${response.status}).

What it means

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.

Solutions

  1. Upgrade the org to an enterprise plan if the error is the 402 enterprise-plan message.
  2. Validate the DesktopPolicyPayload shape client-side before POSTing to pass server validation.
  3. Re-authenticate if the error indicates an expired/reauth-needed session.
  4. Retry as a user with policy-management permissions.
  5. For 5xx, check Den server logs.

Example fix

// before
if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
throw getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);
// after
if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
if (response.status === 400) throw new Error(getErrorMessage(payload, "Invalid policy settings - check the form values."));
throw getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);
Defensive patterns

Strategy: try-catch

Validate before calling

function policyPayloadOk(p: DesktopPolicyPayload): boolean {
  return typeof p.name === "string" && p.name.trim().length > 0; // + rule schema checks
}
if (!policyPayloadOk(input)) throw new Error("Invalid policy payload");

Type guard

function isEnterprisePlanError(e: unknown): boolean { return e instanceof Error && e.message === DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR; }

Try / catch

try {
  await createDesktopPolicy(input);
} catch (error) {
  if (isEnterprisePlanError(error)) { showUpgradePrompt(); return; }
  if (isReauthRequiredError(error)) { promptReauth(); return; }
  showToast(error.message);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/72459ff130c89034. Report an issue: GitHub.

Appendix: source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/desktop-policy-data.tsx:201

    }
  }

  useEffect(() => {
    void reloadPolicies();
  }, [orgId]);

  return { definitions, desktopPolicies, busy, error, reloadPolicies };
}

export async function createDesktopPolicy(input: DesktopPolicyPayload) {
  const { response, payload } = await requestJson("/v1/desktop-policies", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(input),
  }, 12000);
  if (!response.ok) {
    if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
    throw getRequestError(payload, response, `Failed to create desktop policy (${response.status}).`);
  }
}

export async function updateDesktopPolicy(policyId: string, input: DesktopPolicyPayload) {
  const { response, payload } = await requestJson(`/v1/desktop-policies/${encodeURIComponent(policyId)}`, {
    method: "PATCH",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(input),
  }, 12000);
  if (!response.ok) {
    if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
    throw getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);
  }
}

export async function deleteDesktopPolicy(policyId: string) {
  const { response, payload } = await requestJson(`/v1/desktop-policies/${encodeURIComponent(policyId)}`, {
    method: "DELETE",

View on GitHub (pinned to 2b7df46e8a)