Pacote
    Preparing search index...

    Class BaseError

    Base class for custom errors with repaired subclass prototypes and names.

    Call imprint in subclass constructors on runtimes where extending native Error does not preserve the expected prototype chain.

    import { BaseError } from '@pacote/error'

    class StatusError extends BaseError {
    constructor(public readonly status: number, message?: string) {
    super(message)
    StatusError.imprint(this)
    }
    }

    const error = new StatusError(404, 'Not found')
    error instanceof StatusError // => true
    error.name // => 'StatusError'

    Hierarchy (View Summary)

    Index
    • Creates an error with the provided message.

      Parameters

      • message: string = ''

        Error message; defaults to an empty string.

      Returns BaseError

      The new error instance.

    cause?: unknown
    message: string
    name: string
    stack?: string
    • Creates an instance from an optional message string.

      Parameters

      • Optionalmessage: string

        Error message; defaults to an empty string.

      Returns BaseError

      A new BaseError instance.

    • Indicates whether the argument provided is a built-in Error instance or not.

      Parameters

      • error: unknown

      Returns error is Error