{"record":{"id":"022990d4c89719e5","repo":"discordjs/discord.js","slug":"response-statustext","errorCode":null,"errorMessage":"response.statusText","messagePattern":"response\\.statusText","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/rpc/src/client.ts","lineNumber":369,"sourceCode":"\t\t\tcode,\n\t\t\tgrant_type: 'authorization_code',\n\t\t};\n\n\t\tif (this.options.redirectUri) {\n\t\t\tjsonBody.redirect_uri = this.options.redirectUri;\n\t\t}\n\n\t\tconst response = await fetch(`${RouteBases.api}${Routes.oauth2TokenExchange()}`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/x-www-form-urlencoded',\n\t\t\t},\n\t\t\tbody: new URLSearchParams(jsonBody),\n\t\t\t...options,\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(response.statusText);\n\t\t}\n\n\t\tconst data = (await response.json()) as RESTPostOAuth2AccessTokenResult;\n\n\t\tif (!('access_token' in data)) {\n\t\t\tthrow new Error(JSON.stringify(response));\n\t\t}\n\n\t\treturn data.access_token;\n\t}\n\n\t/**\n\t * Authenticate\n\t *\n\t * @param accessToken - access token\n\t */\n\tpublic async authenticate(accessToken: string, options?: RequestOptions): Promise<this> {\n\t\tconst { application, user } = await this.request(RPCCommands.Authenticate, { access_token: accessToken }, options);","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/rpc/src/client.ts#L351-L387","documentation":"authorize() performs the OAuth2 token exchange with Discord and throws Error(response.statusText) whenever the HTTP response is not ok. The message is just the status text (e.g. 'Unauthorized', 'Bad Request'), meaning the credentials or request body were rejected.","triggerScenarios":"login() with scopes where the token endpoint returns 4xx/5xx: wrong clientId/clientSecret, invalid authorization code, mismatched redirect_uri, or Discord being down.","commonSituations":"Expired or single-use authorization code reused, swapped client id/secret, wrong scopes requested, or network proxies returning error statuses.","solutions":["Log the full response inside a catch and verify clientId/clientSecret against the Discord developer portal","Ensure the authorization code is fresh and matches the same client_id, scopes, and redirect_uri used in the authorize step","Retry later or check status.discordapp.com if the status is 5xx"],"exampleFix":"// before\nconst token = await client.authorize(code, redirect);\n// after\ntry {\n  const token = await client.authorize(code, redirect);\n} catch (err) {\n  console.error('Token exchange failed:', err.message); // e.g. 'Unauthorized'\n}","handlingStrategy":"try-catch","validationCode":"// ensure credentials are non-empty before attempting the exchange\nif (!clientId || !clientSecret) throw new Error('clientId/clientSecret required before authorize()');","typeGuard":null,"tryCatchPattern":"try {\n  await client.login({ clientId, clientSecret, scopes });\n} catch (err) {\n  console.error(`OAuth token exchange failed: ${err.message}`);\n  // inspect status code, refresh code, and retry once\n}","preventionTips":["Use each authorization code exactly once and immediately","Keep clientId/clientSecret/redirect_uri identical across authorize and token steps","Monitor for 5xx and implement one retry with backoff"],"tags":["http","oauth","network"],"backgroundTag":"http-request-failed","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}