fix: handle OAuth error responses returned with HTTP 200 status (#1343)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
This commit is contained in:
Christopher Tso 2026-01-27 02:13:34 +11:00 • committed by GitHub
commit 4b5fdcba02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1088,7 +1088,18 @@ async function executeTokenRequest(
throw await parseErrorResponse(response);
}
return OAuthTokensSchema.parse(await response.json());
const json: unknown = await response.json();
try {
return OAuthTokensSchema.parse(json);
} catch (parseError) {
// Some OAuth servers (e.g., GitHub) return error responses with HTTP 200 status.
// Check for error field only if token parsing failed.
if (typeof json === 'object' && json !== null && 'error' in json) {
throw await parseErrorResponse(JSON.stringify(json));
}
throw parseError;
}
}
/**