Error thrown when an HTTP response has a 4xx or 5xx status code

Thrown by convenience methods (.get, .post, etc.) when throwHttpErrors is enabled (default). Extends FejError so instanceof FejError still catches HTTP errors.

Example

import { createFej, FejHttpError } from 'fej';

const api = createFej();
try {
await api.get('/api/users/999');
} catch (error) {
if (error instanceof FejHttpError) {
console.error(`HTTP ${error.status}: ${error.statusText}`);
console.error('Response body:', error.data);
}
}

Hierarchy (view full)

Constructors

  • Parameters

    • message: string
    • status: number

      HTTP status code (e.g. 404)

    • statusText: string

      HTTP status text (e.g. "Not Found")

    • data: unknown

      Parsed response body

    • headers: Headers

      Response headers

    • Optional context: FejContext

    Returns FejHttpError

Properties

originalError?: Error
context?: FejContext
statusCode?: number
status: number

HTTP status code (e.g. 404)

statusText: string

HTTP status text (e.g. "Not Found")

data: unknown

Parsed response body

headers: Headers

Response headers