UNPKG

@egi/smart-db

Version:

Unified Smart DB Access

1 lines 1.84 kB
"use strict";var __extends=this&&this.__extends||function(){var t=function(r,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},t(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.SmartError=void 0;var smart_log_1=require("@egi/smart-log"),SmartError=function(t){function r(r){var e,o,n,i,s,a,c,p=this,u=["message","name","code","type","location","timestamp","info"];if(void 0===r||"string"==typeof r)e=r;else if("object"==typeof r){if(e="string"==typeof r.message?r.message:"string"==typeof r.text?r.text:"string"==typeof r.error?r.error:"Error",s=r.name,o=r.code,n=r.type,i=r.location,a=r.timestamp,!r.constructor){var l=Object.keys(r).filter(function(t){return!u.includes(t)});l.length>0&&(c={},l.forEach(function(t){c[t]=r[t]}))}}else e="function"==typeof r.toString?r.toString():r;return(p=t.call(this,e)||this).name=null!=s?s:"",p.code=null!=o?o:-1,p.type=null!=n?n:smart_log_1.SmartSeverityLevel.Error,i&&(p.location=i),a&&(p.timestamp=a),c&&(p.info=c),p.smartErrorKeys=u,p}return __extends(r,t),r.prototype.toObject=function(){var t=this,r={name:this.name,message:this.message};return this.smartErrorKeys.forEach(function(e){"name"!=e&&"message"!=e&&t[e]&&(r[e]=t[e])}),r},r.prototype.toString=function(){var r=t.prototype.toString.call(this),e="";return this.type&&(e+=this.type),this.location&&(""!==e&&(e+="-"),e+=this.location),this.code&&(""!==e&&(e+=" #"),e+=this.code),r+" ("+e+")"},r}(Error);exports.SmartError=SmartError;