{"record":{"id":"f3616ff7f7a252d7","repo":"Kong/insomnia","slug":"failed-to-exchange-code-for-token-response-stat","errorCode":null,"errorMessage":"Failed to exchange code for token: ${response.statusText}","messagePattern":"Failed to exchange code for token: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/insomnia/src/sync/git/providers/github.ts","lineNumber":313,"sourceCode":"      // Validate state for security (CSRF protection)\n      if (!PLAYWRIGHT_TEST && !githubStatesCache.has(state)) {\n        throw new Error('Invalid state parameter. It looks like the authorization flow was not initiated by the app.');\n      }\n      const reauthorizingCredentialId = githubStatesCache.get(state);\n\n      // Exchange code for access token via Insomnia backend\n      const response = await net.fetch(getApiBaseURL() + '/v1/oauth/github-app', {\n        method: 'POST',\n        body: JSON.stringify({\n          code,\n        }),\n        headers: {\n          'Content-Type': 'application/json',\n        },\n      });\n\n      if (!response.ok) {\n        throw new Error(`Failed to exchange code for token: ${response.statusText}`);\n      }\n\n      const data = (await response.json()) as GitHubOAuthTokenResponse;\n      const accessTokenExpiresAt = expiresAtFromOAuthExpiresIn(data.expires_in);\n      githubStatesCache.delete(state);\n\n      // Fetch user details\n      const [emails, user] = await Promise.all([\n        this.fetchEmails(data.access_token),\n        this.fetchUser(data.access_token),\n      ]);\n\n      const userProfileEmail = user.email ?? '';\n      const email = emails.find(e => e.primary)?.email ?? userProfileEmail ?? '';\n\n      const author = {\n        email,\n        name: user.name || user.username,","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia/src/sync/git/providers/github.ts#L295-L331","documentation":"Error \"Failed to exchange code for token: ${response.statusText}\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia/src/sync/git/providers/github.ts:313 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}