node-red-contrib-vban
Version:
Nodes to interact with vban protocol
46 lines (45 loc) • 1.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomError = void 0;
const path_1 = __importDefault(require("path"));
class CustomError {
constructor(message = '', payload, exception) {
this.toString = () => {
const obj = Object(this);
if (obj !== this) {
throw new TypeError();
}
const name = this.name || 'Error';
const message = String(this._message) || '';
const strComponents = [];
strComponents.push(`${name} : ${message} \n`);
strComponents.push(this.stack);
return strComponents.join(' ');
};
this.name = 'Error';
if (message instanceof Error) {
exception = message;
message = message.message;
}
this.payload = payload;
const generateStack = () => {
let tmpStack = new Error().stack || '';
if (this.exception) {
tmpStack += '\n=== CAUSED BY ===\n';
tmpStack += `${this.exception.toString()}`;
}
const stack = tmpStack
.split('\n')
.filter((line) => !line.match(new RegExp(`${path_1.default.basename(__filename).replace(/\.js$/, '.ts')}:[0-9]+:[0-9]+\\)`, 'g')));
return `${this.name} : ${this._message}\n${stack.join('\n')}`;
};
this._message = message;
this.message = this._message;
this.exception = typeof exception === typeof '' ? new Error(exception) : exception;
this.stack = generateStack();
}
}
exports.CustomError = CustomError;