@iredium/butterfly
Version:
Express API Framework
55 lines (54 loc) • 2.11 kB
JavaScript
;
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseError = void 0;
var ErrorJSON = /** @class */ (function () {
function ErrorJSON(name, message, code, payload) {
this.name = name;
this.message = message;
this.code = code;
this.payload = payload;
}
return ErrorJSON;
}());
var BaseError = /** @class */ (function (_super) {
__extends(BaseError, _super);
function BaseError(name, message, code, payload) {
if (message === void 0) { message = ''; }
if (code === void 0) { code = 500; }
if (payload === void 0) { payload = {}; }
var _this = _super.call(this, message) || this;
_this.name = name;
_this.message = message;
_this.code = code;
_this.payload = payload;
_this.stack = (new Error(message)).stack;
if (!_this.payload['status']) {
_this.payload['status'] = (code >= 100 && code < 600) ? code : 500;
}
return _this;
}
BaseError.toJSON = function (error) {
var json = new ErrorJSON(error.name, error.message, error.code, error.payload);
return {};
};
BaseError.toString = function (error) {
return JSON.stringify(BaseError.toJSON(error));
};
return BaseError;
}(Error));
exports.BaseError = BaseError;