{"record":{"id":"3dd3639f40061e7a","repo":"different-ai/openwork","slug":"failed-to-connect-github-repository-response-st","errorCode":null,"errorMessage":"Failed to connect GitHub repository (${response.status}).","messagePattern":"Failed to connect GitHub repository \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx","lineNumber":629,"sourceCode":"        \"/v1/connectors/github/setup\",\n        {\n          method: \"POST\",\n          body: JSON.stringify({\n            branch: input.branch,\n            connectorAccountId: input.connectorAccountId,\n            connectorInstanceName: input.connectorInstanceName,\n            installationId: input.installationId,\n            mappings: [],\n            ref: `refs/heads/${input.branch}`,\n            repositoryFullName: input.repositoryFullName,\n            repositoryId: input.repositoryId,\n          }),\n        },\n        20000,\n      );\n\n      if (!response.ok) {\n        throw getRequestError(payload, response, `Failed to connect GitHub repository (${response.status}).`);\n      }\n\n      const item = isRecord(payload) && isRecord(payload.item) ? payload.item : null;\n      const connectorInstance = item && isRecord(item.connectorInstance) ? item.connectorInstance : null;\n      const connectorTarget = item && isRecord(item.connectorTarget) ? item.connectorTarget : null;\n      const connectorInstanceId = connectorInstance ? asString(connectorInstance.id) : null;\n      const connectorTargetId = connectorTarget ? asString(connectorTarget.id) : null;\n      const repositoryFullName = connectorTarget && isRecord(connectorTarget.targetConfigJson)\n        ? asString(connectorTarget.targetConfigJson.repositoryFullName)\n        : null;\n\n      if (!connectorInstanceId || !connectorTargetId || !repositoryFullName) {\n        throw new Error(\"GitHub setup response was incomplete.\");\n      }\n\n        result = {\n        connectorInstanceId,\n        connectorTargetId,","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx#L611-L647","documentation":"Thrown by useCreateGithubConnectorInstance in integration-data.tsx when the Den API's POST to create a GitHub connector instance (which links a GitHub repository installation) returns a non-2xx response. The thrown value comes from getRequestError in ee/apps/den-web/app/(den)/_lib/den-flow.ts:527: it returns a ReauthRequiredError for 403 responses whose payload is {error:'reauth'}, otherwise a plain Error whose message is the server's `error`/`message` field, or the fallback \"Failed to connect GitHub repository (<status>).\" when the payload carries none.","triggerScenarios":"The mutation posts to the GitHub connector-instance endpoint with a 20s timeout via requestJson; it throws whenever response.ok is false. Typical cases: 401/403 (session expired, missing org scope, or 403+{error:'reauth'} triggering a ReauthRequiredError instead), 404 (connector target or installation no longer exists), 409 (repository/connector instance already connected), 422 (invalid installation id or selected repo), 5xx (Den server or upstream GitHub API failure), or the response arriving after the 20000ms timeout window.","commonSituations":"User picks a GitHub App installation whose access was revoked; stale Den session token after long idle; the org plan or connector feature flag disallows GitHub connectors; GitHub webhook setup fails server-side producing a 500; user double-clicks connect and hits a duplicate-instance conflict.","solutions":["Read the actual status code and any server `error` field from the thrown message; handle 403 reauth by routing the user through the sign-in flow (isReauthRequiredError).","If 404/422, verify the GitHub App installation still exists and the user granted repo access, then reconnect from the GitHub install flow.","If 409, list existing connector instances and reuse/connect to the existing instance instead of creating a new one.","If 5xx or network timeout, retry after confirming the Den server is healthy and GitHub status is green."],"exampleFix":"// before\nif (!response.ok) {\n  throw getRequestError(payload, response, `Failed to connect GitHub repository (${response.status}).`);\n}\n// after\nif (!response.ok) {\n  if (isReauthRequiredError(getRequestError(payload, response, \"\"))) {\n    await promptReauth();\n  }\n  if (response.status === 409) {\n    return findExistingConnectorInstance(orgSlug, connectorTargetId);\n  }\n  throw getRequestError(payload, response, `Failed to connect GitHub repository (${response.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"// before calling connectMutation.mutate(...)\nif (!githubInstallationId || typeof githubInstallationId !== \"string\") {\n  throw new Error(\"Select a GitHub App installation before connecting.\");\n}\nif (!navigator.onLine) throw new Error(\"You appear to be offline.\");","typeGuard":"function isReauthError(e: unknown): e is ReauthRequiredError {\n  return e instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  await connectMutation.mutateAsync(input);\n} catch (error) {\n  if (isReauthError(error)) { startReauth(); return; }\n  const status = Number(error.message.match(/\\((\\d{3})\\)/)?.[1] ?? 0);\n  if (status === 409) { reuseExistingInstance(); return; }\n  showToast(error.message);\n}","preventionTips":["Check the mutation's error state (isError/error) and render it inline instead of letting it crash the screen.","Detect isReauthRequiredError and route to sign-in automatically on 403 reauth.","Verify the GitHub App installation exists and is authorized before showing the connect button.","Keep sessions fresh on long-lived dashboard tabs (revalidate on window focus)."],"tags":["http","github-integration","den-api","react-query"],"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"}