{"record":{"id":"e758e2e269198525","repo":"different-ai/openwork","slug":"failed-to-delete-scim-connection-response-statu","errorCode":null,"errorMessage":"Failed to delete SCIM connection (${response.status}).","messagePattern":"Failed to delete SCIM connection \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/scim-screen.tsx","lineNumber":303,"sourceCode":"        \"Delete this SCIM connection? The current bearer token will stop working immediately.\",\n      )\n    ) {\n      return;\n    }\n\n    setError(null);\n    try {\n      await runReauthableAction(\"delete-scim-connection\", async () => {\n        setDeleting(true);\n        try {\n          const { response, payload } = await requestJson(\n            \"/v1/scim\",\n            { method: \"DELETE\" },\n            12000,\n          );\n\n          if (response.status !== 204 && !response.ok) {\n            throw getRequestError(payload, response, `Failed to delete SCIM connection (${response.status}).`);\n          }\n\n          setConnection(null);\n          setVisibleToken(null);\n          setCopiedValue(null);\n          await loadScimConfig();\n        } finally {\n          setDeleting(false);\n        }\n      });\n    } catch (nextError) {\n      setError(\n        nextError instanceof Error ? nextError.message : \"Failed to delete SCIM connection.\",\n      );\n    }\n  }\n\n  if (!orgContext) {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/scim-screen.tsx#L285-L321","documentation":"handleDeleteConnection in scim-screen.tsx throws this when DELETE /v1/scim returns a non-ok status other than 204 (204 and general 2xx are treated as success). Deleting the SCIM connection is destructive — it removes provisioning for the org — so the error means the server refused the removal. Cleanup (clearing token state and reloading config) only runs on success.","triggerScenarios":"DELETE /v1/scim returns 401 (expired session), 403 (non-admin), 404 (connection already deleted elsewhere), or 5xx; anything not 204/ok throws. A concurrent delete by another admin commonly produces the 404 path.","commonSituations":"Two admins clicking delete simultaneously; deleting after the org's SSO binding already removed SCIM; session expiring between loading the screen and confirming the delete dialog.","solutions":["Check status: 404 -> the connection is already gone; just reload the settings screen.","For 401, sign in again; for 403, use an org-admin account.","Retry once after transient 5xx, confirming no other admin deleted it concurrently.","After any failure, reload SCIM config to resync local state before retrying."],"exampleFix":"// before: blind delete\nawait deleteConnection();\n// after: tolerate 'already deleted' gracefully\ntry {\n  await deleteConnection();\n} catch (e) {\n  if (!String(e).includes('404')) throw e;\n}\nawait loadScimConfig();","handlingStrategy":"try-catch","validationCode":"const ok = window.confirm('Delete the SCIM connection? Provisioning for this org will stop.');\nif (!ok) return;","typeGuard":"function isDeletable(v: unknown): v is { connection: Record<string, unknown> } {\n  return typeof v === 'object' && v !== null &&\n    (v as Record<string, unknown>).connection != null;\n}","tryCatchPattern":"try {\n  await deleteConnection();\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.includes('404')) toast('Connection was already deleted.');\n  else if (msg.includes('403')) toast('Only org admins can delete the SCIM connection.');\n  else toast(msg);\n} finally {\n  await loadScimConfig(); // resync local state either way\n}","preventionTips":["Always resync SCIM state after delete attempts (success or 'already gone').","Require a confirmation dialog for this destructive action.","Handle 404 as success-equivalent to make delete idempotent in the UI.","Re-authenticate before confirming deletions in long-open tabs."],"tags":["http","api","scim","destructive-action"],"backgroundTag":"http-non-ok-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}