UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

44 lines (43 loc) 1.5 kB
/** * Error thrown by `HttpRequester` for any non-2xx response from the API. * * Wraps the HTTP status, status text, the parsed response body (JSON when the response * was JSON, raw text otherwise), and the absolute request URL. The `cause` option can * carry an underlying error (e.g. a `SyntaxError` from JSON parsing) so callers can walk * the chain via `err.cause`. * * The class exists so consumers can `instanceof ApiError` and read structured fields * (`err.status`, `err.body`) instead of regexing the message. */ export declare class ApiError extends Error { /** * The HTTP status code returned by the API. */ readonly status: number; /** * The HTTP status text returned by the API. */ readonly statusText: string; /** * The parsed response body. JSON-decoded when the response was JSON, raw string * otherwise. */ readonly body: unknown; /** * The absolute URL of the failing request (after base URL resolution and * `?api=true` injection). */ readonly url: string; /** * Constructor. * * @param status The HTTP status code. * @param statusText The HTTP status text. * @param body The parsed response body. * @param url The absolute URL of the request. * @param options Optional `cause` field for chaining underlying errors. */ constructor(status: number, statusText: string, body: unknown, url: string, options?: { cause?: unknown; }); }