Currently UnexpectedErrorResponseBodyError is thrown even for 200 responses.
export async function sendTokenRequest(request: Request, processResponse?: (obj: unknown) => unknown): Promise<OAuth2Tokens> {
// ...
if (response.status === 200) {
// ...
if (typeof data !== "object" || data === null) {
throw new UnexpectedErrorResponseBodyError(response.status, data);
}
// ...
}
// ...
}
Either add UnexpectedSuccessResponseBodyError or rename UnexpectedErrorResponseBodyError to UnexpectedResponseBodyError.
I did consider keeping the current name but the RFC is explicit about the response statuses:
The authorization server issues an access token and optional refresh token, and constructs the response by adding the following parameters to the entity-body of the HTTP response with a 200 (OK) status code:
The authorization server responds with an HTTP 400 (Bad Request) status code (unless specified otherwise) and includes the following parameters with the response:
Currently
UnexpectedErrorResponseBodyErroris thrown even for 200 responses.Either add
UnexpectedSuccessResponseBodyErroror renameUnexpectedErrorResponseBodyErrortoUnexpectedResponseBodyError.I did consider keeping the current name but the RFC is explicit about the response statuses: