{"record":{"id":"bbb071ff5deb134e","repo":"dubinc/dub","slug":"failed-to-update-workspace","errorCode":null,"errorMessage":"Failed to update workspace.","messagePattern":"Failed to update workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/stripe-app/src/utils/dub.ts","lineNumber":28,"sourceCode":"  token: Token;\n  accountId: string | null;\n  stripeMode: StripeMode;\n}) {\n  const response = await fetch(`${DUB_API_HOST}/stripe/integration`, {\n    method: \"PATCH\",\n    headers: {\n      Authorization: `Bearer ${token.access_token}`,\n    },\n    body: JSON.stringify({\n      stripeAccountId: accountId,\n      stripeMode,\n    }),\n  });\n\n  if (!response.ok) {\n    const data = await response.json();\n\n    throw new Error(\"Failed to update workspace.\", {\n      cause: data.error,\n    });\n  }\n}\n","sourceCodeStart":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/dubinc/dub/blob/f216b94a24ca5a0a48c6543ee10392c9006c8b75/packages/stripe-app/src/utils/dub.ts#L10-L33","documentation":"updateWorkspace in the Stripe app calls the Dub API to update workspace properties (e.g. Stripe connect metadata); when response.ok is false it throws this generic message, attaching the API error payload as `cause` for diagnosis. The generic text hides the real reason, which must be read from error.cause.","triggerScenarios":"The workspace-update request (packages/stripe-app/src/utils/dub.ts) receives a non-OK status: invalid/explicitly missing bearer token, workspace id mismatch, or the Dub API rejecting the update payload with 4xx/5xx.","commonSituations":"User disconnects/reconnects Stripe with a stale Dub token; workspace was deleted on Dub's side; API validation rejects the update during Stripe webhook/account session flows.","solutions":["Log/inspect error.cause — it holds the API's error object with the concrete code and message.","Re-run the Dub OAuth flow to obtain a fresh token if the cause indicates authentication failure.","Verify the workspace id being sent still exists in Dub.","Retry the update; if persistent, check the request payload against the Dub API docs."],"exampleFix":"// before\ncatch (e) { console.error(e.message); } // \"Failed to update workspace.\"\n// after\ncatch (e) { console.error(e.message, e.cause); } // includes API error detail","handlingStrategy":"try-catch","validationCode":"const token = await getSecret({ stripe, name: \"dub_token\" });\nif (!token) throw new Error(\"Dub not connected for this account; skipping workspace update\");\nif (!workspaceId) throw new Error(\"workspaceId is required before calling updateWorkspace\");","typeGuard":"function hasErrorCause(e: unknown): e is Error & { cause: { code?: string; message?: string } } {\n  return e instanceof Error && typeof e.cause === \"object\" && e.cause !== null;\n}","tryCatchPattern":"try {\n  await updateWorkspace({ ... });\n} catch (e) {\n  if (hasErrorCause(e)) console.error(\"Workspace update failed:\", e.message, e.cause);\n  else throw e;\n}","preventionTips":["Always inspect e.cause for the underlying API error code.","Re-run OAuth when the cause indicates 401/403.","Verify workspace existence before updating.","Alert on repeated update failures instead of failing silently."],"tags":["api","stripe","workspace"],"backgroundTag":"api-error-response","analyzedSha":"f216b94a24ca5a0a48c6543ee10392c9006c8b75","analyzedAt":"2026-08-31T18:35:50.395Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}