{"record":{"id":"ae1f906f9c12081b","repo":"mastra-ai/mastra","slug":"slack-oauth-http-error-tokenresponse-status","errorCode":null,"errorMessage":"Slack OAuth HTTP error: ${tokenResponse.status} ${tokenResponse.statusText}","messagePattern":"Slack OAuth HTTP error: (.+?) (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/slack/src/provider.ts","lineNumber":1424,"sourceCode":"      throw new Error('SlackProvider baseUrl not available during OAuth callback');\n    }\n\n    try {\n      // Exchange code for tokens\n      const tokenResponse = await fetch('https://slack.com/api/oauth.v2.access', {\n        method: 'POST',\n        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n        body: new URLSearchParams({\n          client_id: pending.clientId,\n          client_secret: pending.clientSecret,\n          code,\n          redirect_uri: `${baseUrl}/slack/oauth/callback`,\n        }),\n        signal: AbortSignal.timeout(30_000),\n      });\n\n      if (!tokenResponse.ok) {\n        throw new Error(`Slack OAuth HTTP error: ${tokenResponse.status} ${tokenResponse.statusText}`);\n      }\n\n      const tokenData = (await tokenResponse.json()) as {\n        ok: boolean;\n        error?: string;\n        access_token?: string;\n        bot_user_id?: string;\n        team?: { id: string; name: string };\n      };\n\n      if (!tokenData.ok) {\n        throw new Error(`OAuth failed: ${tokenData.error}`);\n      }\n\n      if (!tokenData.access_token || !tokenData.bot_user_id || !tokenData.team?.id) {\n        throw new Error('Slack OAuth response missing required fields (access_token, bot_user_id, or team)');\n      }\n","sourceCodeStart":1406,"sourceCodeEnd":1442,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/channels/slack/src/provider.ts#L1406-L1442","documentation":"The provider exchanges the OAuth code at https://slack.com/api/oauth.v2.access and checks response.ok. Slack returned a non-2xx HTTP status, so the provider surfaces the status/statusText. This is a transport-level failure — Slack itself rejected the request before any OAuth semantics (ok/error payload) could be evaluated.","triggerScenarios":"POST to slack.com/api/oauth.v2.access returns 4xx/5xx — e.g. invalid client_id/client_secret (401/400), Slack 5xx outage, or a proxy/gateway erroring before Slack is reached.","commonSituations":"Wrong SLACK_CLIENT_ID/SLACK_CLIENT_SECRET env vars in the deployment; corporate proxy intercepting outbound HTTPS; Slack incident causing 503s during install.","solutions":["Verify client_id and client_secret sent with the token exchange match the Slack app credentials.","Retry the OAuth flow after checking Slack's status page if the status is 5xx.","Check network/proxy configuration that could block or alter requests to slack.com.","Log tokenResponse.status/body to confirm whether the failure is auth-related (400/401) or infrastructure (5xx)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await completeSlackOAuth(code);\n} catch (e) {\n  const m = /Slack OAuth HTTP error: (\\d+)/.exec(e.message);\n  if (m && +m[1] >= 500) {\n    await retryWithBackoff(() => completeSlackOAuth(code), 3); // or restart flow if code expired\n  } else throw e;\n}","preventionTips":["Verify SLACK_CLIENT_ID/SLACK_CLIENT_SECRET in every environment at boot.","Monitor Slack's status page and add alerting on 5xx rates during installs.","Ensure egress (proxies/firewalls) allows HTTPS to slack.com."],"tags":["slack","oauth","http","network"],"backgroundTag":"http-5xx","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}