Kong/insomnia · error
Failed to exchange code for token: ${response.statusText}
Error message
Failed to exchange code for token: ${response.statusText} What it means
Error "Failed to exchange code for token: ${response.statusText}" thrown in Kong/insomnia.
Source
Thrown at packages/insomnia/src/sync/git/providers/github.ts:313
// Validate state for security (CSRF protection)
if (!PLAYWRIGHT_TEST && !githubStatesCache.has(state)) {
throw new Error('Invalid state parameter. It looks like the authorization flow was not initiated by the app.');
}
const reauthorizingCredentialId = githubStatesCache.get(state);
// Exchange code for access token via Insomnia backend
const response = await net.fetch(getApiBaseURL() + '/v1/oauth/github-app', {
method: 'POST',
body: JSON.stringify({
code,
}),
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to exchange code for token: ${response.statusText}`);
}
const data = (await response.json()) as GitHubOAuthTokenResponse;
const accessTokenExpiresAt = expiresAtFromOAuthExpiresIn(data.expires_in);
githubStatesCache.delete(state);
// Fetch user details
const [emails, user] = await Promise.all([
this.fetchEmails(data.access_token),
this.fetchUser(data.access_token),
]);
const userProfileEmail = user.email ?? '';
const email = emails.find(e => e.primary)?.email ?? userProfileEmail ?? '';
const author = {
email,
name: user.name || user.username,View on GitHub (pinned to d9bb2b0142)
When it happens
Trigger: Thrown at packages/insomnia/src/sync/git/providers/github.ts:313 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26).
Data as JSON: /api/errors/f3616ff7f7a252d7.
Report an issue: GitHub.