unifi-client
Version:
NodeJs client for Unifi products (https://www.ui.com/)
57 lines (56 loc) • 2.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.__Error = void 0;
var path_1 = __importDefault(require("path"));
var EErrorsCodes_1 = require("./EErrorsCodes");
var __Error = /** @class */ (function () {
function __Error(message, code, exception) {
if (message === void 0) { message = ''; }
if (code === void 0) { code = EErrorsCodes_1.EErrorsCodes.UNKNOWN_ERROR; }
var _this = this;
this.toString = function () {
var obj = Object(_this);
if (obj !== _this) {
throw new TypeError();
}
var name = _this.name || 'Error';
var message = String(_this._message) || '';
var strComponents = [];
var errorCodeStr = _this.errorCode ? " (".concat(_this.errorCode, ")") : '';
strComponents.push("".concat(name).concat(errorCodeStr, " : ").concat(message, " \n"));
strComponents.push(_this.stack);
return strComponents.join(' ');
};
this.name = 'Error';
if (message instanceof Error) {
exception = message;
message = message.message;
}
this.errorCode = code;
this.code = code;
var generateStack = function () {
var tmpStack = new Error().stack || '';
if (_this.exception) {
tmpStack += '\n=== CAUSED BY ===\n';
tmpStack += "".concat(_this.exception.toString());
}
var stack = tmpStack
.split('\n')
.filter(function (line) { return !line.match(new RegExp("".concat(path_1.default.basename(__filename).replace(/\.js$/, '.ts'), ":[0-9]+:[0-9]+\\)"), 'g')); });
//remove two last line from stack
return "".concat(_this.name, " : ").concat(_this._message, "\n").concat(stack.join('\n'));
};
this._message = message;
this.message = this._message;
this.exception = typeof exception === typeof '' ? new Error(exception) : exception;
this.stack = generateStack();
// TODO I don't remember why this is important
// Set the prototype explicitly.
// Object.setPrototypeOf(this, Error.prototype);
}
return __Error;
}());
exports.__Error = __Error;