This module provides a base class for creating error classes with error code (class name), message template, meta data support out of the box.
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); // MyAwesomeErrorthrow 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) Copy
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); // MyAwesomeErrorthrow 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)
Optional
Rest
Private
Static
Optional override for formatting stack traces
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Create .stack property on a target object
Generated using TypeDoc
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