UNPKG

@atproto/oauth-client

Version:

OAuth client for ATPROTO PDS. This package serves as common base for environment-specific implementations (NodeJS, Browser, React-Native).

32 lines (24 loc) 809 B
import { Json, ifString, ifObject } from '@atproto-labs/fetch' export class OAuthResponseError extends Error { readonly error?: string readonly errorDescription?: string constructor( public readonly response: Response, public readonly payload: Json, ) { const error = ifString(ifObject(payload)?.['error']) const errorDescription = ifString(ifObject(payload)?.['error_description']) const messageError = error ? `"${error}"` : 'unknown' const messageDesc = errorDescription ? `: ${errorDescription}` : '' const message = `OAuth ${messageError} error${messageDesc}` super(message) this.error = error this.errorDescription = errorDescription } get status() { return this.response.status } get headers() { return this.response.headers } }