@egi/smart-db
Version:
Unified Smart DB Access
1 lines • 1.27 kB
JavaScript
export const SmartErrorLocation={App:"APP",Frontend:"FRONTEND",Backend:"BACKEND",Database:"DATABASE",UpgradeManager:"UPGRADE-MANAGER"};export const SmartErrorSeverity={Fatal:"F",Error:"E",Warning:"W",Info:"I",Debug:"D",Local:"L"};export class SmartError extends Error{constructor(t){let e,r,s,o,i,n,a;if(void 0===t||"string"==typeof t)e=t;else if("object"==typeof t){if(e="string"==typeof t.message?t.message:"string"==typeof t.text?t.text:"string"==typeof t.error?t.error:"Error",i=t.name,r=t.code,s=t.type,o=t.location,n=t.timestamp,!t.constructor){const e=Object.keys(t).filter((t=>!this.smartErrorKeys.includes(t)));e.length>0&&(a={},e.forEach((e=>{a[e]=t[e]})))}}else e="function"==typeof t.toString?t.toString():t;super(e),this.name=i??"",this.code=r??-1,this.type&&(this.type=s??"E"),o&&(this.location=o),n&&(this.timestamp=n),a&&(this.info=a),this.smartErrorKeys=["message","name","code","type","location","timestamp","info"]}toObject(){const t={name:this.name,message:this.message};return this.smartErrorKeys.forEach((e=>{"name"!=e&&"message"!=e&&this[e]&&(t[e]=this[e])})),t}toString(){let t=super.toString(),e="";return this.type&&(e+=this.type),this.location&&(""!==e&&(e+="-"),e+=this.location),this.code&&(""!==e&&(e+=" #"),e+=this.code),t+" ("+e+")"}}