ChemPal Documentation - v1.18.0
    Preparing search index...

    Error thrown when an HTTP response has a non-2xx status. Carries the numeric status so callers can branch on it (e.g. retrying a 403 WAF cookie challenge) rather than string-matching the message.

    The HTTP status code (e.g. 403)

    The HTTP status text (e.g. "Forbidden")

    The (truncated) response body, when it could be read

    The HttpError instance

    try {
    await fetchDecorator(url);
    } catch (error) {
    if (error instanceof HttpError && error.status === 403) {
    // retry the request
    }
    if (error instanceof HttpError && error.body?.includes('INVALID_API_KEY')) {
    // the API told us why it refused the request
    }
    }
    export class HttpError extends Error {
    public readonly status: number;
    public readonly statusText: string;
    public readonly body?: string;
    constructor(status: number, statusText: string, body?: string) {
    super(statusText ? `HTTP Error: ${status} ${statusText}` : `HTTP Error: ${status}`);
    this.name = 'HttpError';
    this.status = status;
    this.statusText = statusText;
    this.body = body;
    }
    }

    Hierarchy

    Index

    Constructors

    Properties

    Constructors

    Properties

    status: number
    statusText: string
    body?: string