different-ai/openwork · error · Error

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

Error message

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

What it means

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.

Source

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

    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",
  }, 12000);
  if (!response.ok) {
    throw getRequestError(payload, response, `Failed to delete desktop policy (${response.status}).`);
  }
}

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. If 402/enterprise-plan message: upgrade the org plan or stop editing policies.
  2. Refresh the policy list to confirm the policy still exists (404).
  3. Validate the payload fields before PATCHing.
  4. Re-authenticate on reauth-required errors and retry the toggle/save.
  5. Check server logs on 5xx.

Example fix

// before
if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
throw getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);
// after
if (response.status === 402) throw new Error(DESKTOP_POLICY_ENTERPRISE_PLAN_ERROR);
if (response.status === 404) throw new Error("This policy no longer exists - refresh the list.");
throw getRequestError(payload, response, `Failed to update desktop policy (${response.status}).`);
Defensive patterns

Strategy: try-catch

Validate before calling

const exists = policies.some((p) => p.id === policyId);
if (!exists) { refreshPolicies(); return; } // avoid 404 on stale row

Type guard

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

Try / catch

try {
  await updateDesktopPolicy(policyId, input);
} catch (error) {
  if (isEnterprisePlanError(error)) { showUpgradePrompt(); return; }
  if (error instanceof Error && /404/.test(error.message)) { refreshPolicies(); return; }
  showToast(error.message);
}

Prevention

When it happens

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

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

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/7a2cf818bf30bdb9. Report an issue: GitHub.