Skip to content

Update 200 response body parsing errors #305

@pilcrowonpaper

Description

@pilcrowonpaper

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions