@vsokolov/utils - v0.32.0
    Preparing search index...

    Interface ErrorWithStatus

    Extended Error interface with optional HTTP status code support. This enables consistent error handling with status codes across the application.

    throw Object.assign(new Error('User not found'), { status: 404 });

    // Or with custom class:
    class ApiError extends Error implements ErrorWithStatus {
    constructor(message: string, public status?: number) {
    super(message);
    }
    }
    interface ErrorWithStatus {
        status?: number;
    }

    Hierarchy

    • Error
      • ErrorWithStatus
    Index

    Properties

    Properties

    status?: number

    HTTP status code associated with the error (e.g., 400, 404, 500)