UNPKG

@speedup/error

Version:
45 lines (44 loc) 1.6 kB
"use strict"; /** * Error base class */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var util_1 = require("./util"); var ErrorBase = /** @class */ (function (_super) { __extends(ErrorBase, _super); function ErrorBase(config) { var _this = this; if (!config) { throw new Error('E_NO_CONFIG'); } // generate error message var errorMessage = util_1.getEitherDefaultOrPredefinedErrorMessage(config); _this = _super.call(this, errorMessage) || this; _this.code = config.code; _this.message = errorMessage; if (config.error) { // copy the default stacktrace _this.stack = config.error.stack; } // set stacktrace Error.captureStackTrace(_this, ErrorBase); // Set prototype to make instanceOf enabled Object.setPrototypeOf(_this, ErrorBase.prototype); return _this; } return ErrorBase; }(Error)); exports.ErrorBase = ErrorBase;