Class BaseError

Description

This module provides a base class for creating error classes with error code (class name), message template, meta data support out of the box.

Example

import { BaseError } from '@biorate/errors';

export class MyAwesomeError extends BaseError {
constructor(args?: unknown[], meta?: unknown) {
super(`Oops... Some error happen, at [%s], in [%s]`, args, meta);
}
}

const e = new MyAwesomeError([new Date(), 'core'], { hello: 'world!' });

console.log(e.meta); // { hello: 'world!' }
console.log(e.code); // MyAwesomeError

throw e;
^
MyAwesomeError: Oops... Some error happen, at [2021-05-13T09:19:22.511Z], in [core]
at Object.<anonymous> (..core/packages/@biorate/errors/index.ts:28:11)
at Module._compile (internal/modules/cjs/loader.js:1138:30)

Hierarchy

  • Error
    • BaseError

Constructors

Properties

#meta: any = null
cause?: unknown
message: string
name: string
stack?: string
prepareStackTrace?: ((err, stackTraces) => any)

Type declaration

stackTraceLimit: number

Accessors

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function
      Optional

    Returns void

Generated using TypeDoc