error-express
Version:
Are you tired of messy error handling in your Express apps? Say goodbye to confusion and frustration with **`error-express`**, a powerful NPM package designed to streamline error management in your Express applications.
2 lines • 1.23 kB
JavaScript
import l from"express/lib/router/layer";import a from"express/lib/router";var m=(t=[])=>t[t.length-1],d=Function.prototype;function g(t,s){return Object.keys(t).forEach(e=>{s[e]=t[e]}),s}function i(t){let s=function(...r){let n=t.apply(this,r),c=(r.length===5?r[2]:m(r))||d;return n&&n.catch&&n.catch(p=>c(p)),n};return Object.defineProperty(s,"length",{value:t.length,writable:!1}),g(t,s)}function h(){let t=a.prototype.constructor.param;a.prototype.constructor.param=function(e,r){return r=i(r),t.call(this,e,r)}}Object.defineProperty(l.prototype,"handle",{enumerable:!0,get(){return this.__handle},set(t){t=i(t),this.__handle=t}});h();var o=class extends Error{statusCode;constructor(s,e){super(s),this.statusCode=e}serializeErrors(){return{message:this.message,status:this.status,statusCode:this.statusCode}}},u=class extends o{status="error";constructor(s,e){super(s,e||500)}},x=(t,s,e,r)=>{try{t instanceof o?e.status(t.serializeErrors().statusCode).json(t.serializeErrors()):e.status(500).json({message:t?.message||"Server Error",statusCode:500})}catch{e.status(500).json({message:"Something went wrong",statusCode:500})}};export{o as CustomError,u as ServerError,x as globalErrorHandler};
//# sourceMappingURL=index.mjs.map