UNPKG

@lakutata/core

Version:

Lakutata Framework Core

60 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Exception = void 0; const pupa = require("pupa"); const util_1 = require("util"); class Exception extends Error { constructor(errArgs) { super(); this.appId = process.env.appId ? process.env.appId : 'Unknown'; this.appName = process.env.appName ? process.env.appName : 'Unknown'; const _errArgs = Array.isArray(errArgs) ? errArgs : [errArgs]; this.message = (() => { let errorMessage = null; try { const argumentRegExs = []; for (const errArg of _errArgs) { argumentRegExs.push(new RegExp(errArg)); } for (const template of this.templates()) { const str = pupa(template, _errArgs); let satisfied = true; try { argumentRegExs.forEach(argumentRegEx => { if (satisfied) { if (!argumentRegEx.test(str)) satisfied = false; } }); } catch (e) { satisfied = false; } if (satisfied) { errorMessage = str; break; } } } catch (e) { errorMessage = null; } if (errorMessage) { return errorMessage; } else { return util_1.format.apply(util_1.format, _errArgs); } })(); this.errMsg = this.message; this.err = this.name; } get name() { return this.constructor.name; } templates() { return []; } } exports.Exception = Exception; //# sourceMappingURL=Exception.js.map