mastra-ai/mastra · error

Slack OAuth HTTP error: ${tokenResponse.status} ${tokenRespo

Error message

Slack OAuth HTTP error: ${tokenResponse.status} ${tokenResponse.statusText}

What it means

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.

Source

Thrown at channels/slack/src/provider.ts:1424

      throw new Error('SlackProvider baseUrl not available during OAuth callback');
    }

    try {
      // Exchange code for tokens
      const tokenResponse = await fetch('https://slack.com/api/oauth.v2.access', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams({
          client_id: pending.clientId,
          client_secret: pending.clientSecret,
          code,
          redirect_uri: `${baseUrl}/slack/oauth/callback`,
        }),
        signal: AbortSignal.timeout(30_000),
      });

      if (!tokenResponse.ok) {
        throw new Error(`Slack OAuth HTTP error: ${tokenResponse.status} ${tokenResponse.statusText}`);
      }

      const tokenData = (await tokenResponse.json()) as {
        ok: boolean;
        error?: string;
        access_token?: string;
        bot_user_id?: string;
        team?: { id: string; name: string };
      };

      if (!tokenData.ok) {
        throw new Error(`OAuth failed: ${tokenData.error}`);
      }

      if (!tokenData.access_token || !tokenData.bot_user_id || !tokenData.team?.id) {
        throw new Error('Slack OAuth response missing required fields (access_token, bot_user_id, or team)');
      }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify client_id and client_secret sent with the token exchange match the Slack app credentials.
  2. Retry the OAuth flow after checking Slack's status page if the status is 5xx.
  3. Check network/proxy configuration that could block or alter requests to slack.com.
  4. Log tokenResponse.status/body to confirm whether the failure is auth-related (400/401) or infrastructure (5xx).
Defensive patterns

Strategy: retry

Try / catch

try {
  await completeSlackOAuth(code);
} catch (e) {
  const m = /Slack OAuth HTTP error: (\d+)/.exec(e.message);
  if (m && +m[1] >= 500) {
    await retryWithBackoff(() => completeSlackOAuth(code), 3); // or restart flow if code expired
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Wrong SLACK_CLIENT_ID/SLACK_CLIENT_SECRET env vars in the deployment; corporate proxy intercepting outbound HTTPS; Slack incident causing 503s during install.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/ae1f906f9c12081b. Report an issue: GitHub.