UNPKG

@elsikora/cladi

Version:

Zero-dependency TypeScript DI toolkit with typed tokens and scoped lifecycles.

42 lines (39 loc) 1.03 kB
'use strict'; /** * Base error class. * @see {@link https://elsikora.com/docs/cladi/core-concepts/error-handling} */ class BaseError extends Error { get cause() { return super.cause; } get code() { return this.CODE; } get context() { return this.CONTEXT; } get source() { return this.SOURCE; } CODE; CONTEXT; SOURCE; /** * Creates a new base error. * @param {string} message Error message. * @param {IBaseErrorOptions} options Error options. */ constructor(message, options) { super(message, options.cause ? { cause: options.cause } : undefined); this.name = this.constructor.name; this.CODE = options.code; this.CONTEXT = options.context; this.SOURCE = options.source; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, this.constructor); } } } exports.BaseError = BaseError; //# sourceMappingURL=error.class.js.map