UNPKG

@elsikora/cladi

Version:

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

40 lines (38 loc) 1.01 kB
/** * 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); } } } export { BaseError }; //# sourceMappingURL=error.class.js.map