different-ai/openwork · error · Error
Failed to disconnect integration (${response.status}).
Error message
Failed to disconnect integration (${response.status}). What it means
Thrown when disconnecting an integration fails. For connections with a connectionId the code POSTs {reason:'Disconnected from Den Web integrations.'} to the disconnect endpoint (20s timeout) and throws getRequestError on non-ok; otherwise it falls back to a simulated-latency local disconnect path. getRequestError (den-flow.ts:527) may instead return a ReauthRequiredError for 403 {error:'reauth'}.
Source
Thrown at ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx:900
const queryClient = useQueryClient();
const { runReauthableAction } = useOrgDashboard();
return useMutation({
mutationFn: async (connectionId: string) => {
let result: string | null = null;
await runReauthableAction("disconnect-integration", async () => {
const isGithubConnection = connectionId.startsWith("cac_");
if (isGithubConnection) {
const { response, payload } = await requestJson(
`/v1/connector-accounts/${encodeURIComponent(connectionId)}/disconnect`,
{
method: "POST",
body: JSON.stringify({ reason: "Disconnected from Den Web integrations." }),
},
20000,
);
if (!response.ok) {
throw getRequestError(payload, response, `Failed to disconnect integration (${response.status}).`);
}
result = connectionId;
return;
}
await simulateLatency(300);
mockConnections = mockConnections.filter((entry) => entry.id !== connectionId);
result = connectionId;
});
if (!result) {
throw new Error("Disconnect response was incomplete.");
}
return result;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: integrationQueryKeys.all });
queryClient.invalidateQueries({ queryKey: ["plugins"] });
},View on GitHub (pinned to 2b7df46e8a)
Solutions
- On 404, treat the integration as already disconnected: refresh the integration list and clear local state.
- On 401/403, run the reauth/sign-in flow (check isReauthRequiredError) then retry.
- If the server says the connection is in use, remove dependent policies/automations first, then disconnect.
- On 5xx/timeout, retry the disconnect; it is idempotent per connectionId.
Example fix
// before
if (!response.ok) {
throw getRequestError(payload, response, `Failed to disconnect integration (${response.status}).`);
}
// after
if (!response.ok) {
if (response.status === 404) {
return connectionId; // already gone server-side
}
throw getRequestError(payload, response, `Failed to disconnect integration (${response.status}).`);
} Defensive patterns
Strategy: try-catch
Validate before calling
// before disconnecting
if (!connectionId) throw new Error("No server-side connection to disconnect.");
// optionally confirm no dependents:
const dependents = getDependentPolicies(integrationId);
if (dependents.length > 0) throw new Error("Remove linked policies first."); Type guard
function isReauthError(e: unknown): e is ReauthRequiredError {
return e instanceof ReauthRequiredError;
} Try / catch
try {
await disconnectMutation.mutateAsync({ connectionId });
} catch (error) {
if (isReauthError(error)) { startReauth(); return; }
if (/\(404\)/.test(error.message)) { clearLocalIntegration(integrationId); return; }
showToast(error.message);
} Prevention
- Refresh the integration list before disconnecting to avoid 404 on already-removed connections.
- Make the disconnect button idempotent: 404 means success.
- Check for dependent policies/automations client-side before calling the API.
- Require confirmation dialog so a stray click does not fire the POST.
When it happens
Trigger: The disconnect POST returns non-ok: 401/403 (session expired, no permission on the integration, or reauth required), 404 (connection already removed server-side), 409/422 (connection is in use by active runs or policies), 5xx (provider or Den server failure).
Common situations: Trying to disconnect an integration another admin already removed; org policy blocks disconnecting a connector that desktop policies depend on; stale tab with an expired session; provider outage during disconnect cleanup.
Related errors
- Failed to connect GitHub repository (${response.status}).
- Failed to apply GitHub discovery (${response.status}).
- Failed to update auto-import (${response.status}).
- Failed to sync connector instance (${response.status}).
- Failed to remove connector instance (${response.status}).
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/e4da1228c24d4862.
Report an issue: GitHub.