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:
parent
b2326afea6
commit
4b5fdcba02
1 changed files with 63 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue