@happy-ts/fetch-t
    Preparing search index...

    Class FetchError

    Custom error class for HTTP error responses (non-2xx status codes).

    Thrown when Response.ok is false. Contains the HTTP status code for programmatic error handling.

    import { fetchT, FetchError } from '@happy-ts/fetch-t';

    const result = await fetchT('https://api.example.com/not-found', {
    responseType: 'json',
    });

    result.inspectErr((err) => {
    if (err instanceof FetchError) {
    console.log('HTTP Status:', err.status); // e.g., 404
    console.log('Status Text:', err.message); // e.g., "Not Found"

    // Handle specific status codes
    switch (err.status) {
    case 401:
    console.log('Unauthorized - please login');
    break;
    case 404:
    console.log('Resource not found');
    break;
    case 500:
    console.log('Server error');
    break;
    }
    }
    });

    Hierarchy

    • Error
      • FetchError
    Index

    Constructors

    Properties

    Constructors

    • Creates a new FetchError instance.

      Parameters

      • message: string

        The status text from the HTTP response (e.g., "Not Found").

      • status: number

        The HTTP status code (e.g., 404).

      Returns FetchError

    Properties

    name: string = 'FetchError'

    The error name, always 'FetchError'.

    status: number

    The HTTP status code of the response (e.g., 404, 500).