@ingeze/api-error - v1.0.8
    Preparing search index...

    Class ErrorHandler

    Custom error handler class for the application.

    Extends the base Error class and allows defining errors with additional information such as type, HTTP status code, message, and optional details.

    throw new ErrorHandler('User not found', 404, 'NOT_FOUND')
    

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new instance of ErrorHandler.

      Parameters

      • message: string

        Descriptive error message.

      • OptionalstatusCode: number = 500

        HTTP status code (default is 500).

      • Optionaltype: string = 'GENERIC_ERROR'

        Error type.

      • Optionaldetails: Record<string, unknown>

        Additional error details (optional).

      Returns ErrorHandler

    Properties

    details?: Record<string, unknown>

    Additional error details (optional).

    message: string

    Descriptive error message.

    statusCode: number

    HTTP status code associated with the error.

    success: boolean

    Indicates if the response was successful (always false for errors).

    type: string

    Error type.

    Methods

    • Converts the error instance to a JSON object compatible with the ErrorResponse interface.

      Returns ErrorResponse

      Serializable error object.