UNPKG

error-express

Version:

A lightweight, zero-dependency package to handle global errors in Express.js applications. It catches unhandled errors and provides a simple, yet powerful way to manage them.

2 lines 7.31 kB
import y from"express/lib/router/layer";import Y from"express/lib/router";var t={CONTINUE:100,SWITCHING_PROTOCOLS:101,PROCESSING:102,EARLY_HINTS:103,OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511},s={[t.CONTINUE]:"Continue",[t.SWITCHING_PROTOCOLS]:"Switching Protocols",[t.PROCESSING]:"Processing",[t.EARLY_HINTS]:"Early Hints",[t.OK]:"OK",[t.CREATED]:"Created",[t.ACCEPTED]:"Accepted",[t.NON_AUTHORITATIVE_INFORMATION]:"Non-Authoritative Information",[t.NO_CONTENT]:"No Content",[t.RESET_CONTENT]:"Reset Content",[t.PARTIAL_CONTENT]:"Partial Content",[t.MULTI_STATUS]:"Multi-Status",[t.ALREADY_REPORTED]:"Already Reported",[t.IM_USED]:"IM Used",[t.MULTIPLE_CHOICES]:"Multiple Choices",[t.MOVED_PERMANENTLY]:"Moved Permanently",[t.FOUND]:"Found",[t.SEE_OTHER]:"See Other",[t.NOT_MODIFIED]:"Not Modified",[t.USE_PROXY]:"Use Proxy",[t.TEMPORARY_REDIRECT]:"Temporary Redirect",[t.PERMANENT_REDIRECT]:"Permanent Redirect",[t.BAD_REQUEST]:"Bad Request",[t.UNAUTHORIZED]:"Unauthorized",[t.PAYMENT_REQUIRED]:"Payment Required",[t.FORBIDDEN]:"Forbidden",[t.NOT_FOUND]:"Not Found",[t.METHOD_NOT_ALLOWED]:"Method Not Allowed",[t.NOT_ACCEPTABLE]:"Not Acceptable",[t.PROXY_AUTHENTICATION_REQUIRED]:"Proxy Authentication Required",[t.REQUEST_TIMEOUT]:"Request Timeout",[t.CONFLICT]:"Conflict",[t.GONE]:"Gone",[t.LENGTH_REQUIRED]:"Length Required",[t.PRECONDITION_FAILED]:"Precondition Failed",[t.PAYLOAD_TOO_LARGE]:"Payload Too Large",[t.URI_TOO_LONG]:"URI Too Long",[t.UNSUPPORTED_MEDIA_TYPE]:"Unsupported Media Type",[t.RANGE_NOT_SATISFIABLE]:"Range Not Satisfiable",[t.EXPECTATION_FAILED]:"Expectation Failed",[t.IM_A_TEAPOT]:"I'm a teapot",[t.MISDIRECTED_REQUEST]:"Misdirected Request",[t.UNPROCESSABLE_ENTITY]:"Unprocessable Entity",[t.LOCKED]:"Locked",[t.FAILED_DEPENDENCY]:"Failed Dependency",[t.TOO_EARLY]:"Too Early",[t.UPGRADE_REQUIRED]:"Upgrade Required",[t.PRECONDITION_REQUIRED]:"Precondition Required",[t.TOO_MANY_REQUESTS]:"Too Many Requests",[t.REQUEST_HEADER_FIELDS_TOO_LARGE]:"Request Header Fields Too Large",[t.UNAVAILABLE_FOR_LEGAL_REASONS]:"Unavailable For Legal Reasons",[t.INTERNAL_SERVER_ERROR]:"Internal Server Error",[t.NOT_IMPLEMENTED]:"Not Implemented",[t.BAD_GATEWAY]:"Bad Gateway",[t.SERVICE_UNAVAILABLE]:"Service Unavailable",[t.GATEWAY_TIMEOUT]:"Gateway Timeout",[t.HTTP_VERSION_NOT_SUPPORTED]:"HTTP Version Not Supported",[t.VARIANT_ALSO_NEGOTIATES]:"Variant Also Negotiates",[t.INSUFFICIENT_STORAGE]:"Insufficient Storage",[t.LOOP_DETECTED]:"Loop Detected",[t.NOT_EXTENDED]:"Not Extended",[t.NETWORK_AUTHENTICATION_REQUIRED]:"Network Authentication Required"};var g=e=>Object.keys(t).find(R=>t[R]===e)??"INTERNAL_SERVER_ERROR",T=class e extends Error{constructor(R,O,o=!0,n){super(R);this.message=R;this.statusCode=O;this.isOparational=o;this.code=n??g(O),Object.setPrototypeOf(this,e.prototype)}code},r=class extends T{constructor(E,R=t.INTERNAL_SERVER_ERROR){super(E,R,!0)}},_=class extends T{constructor(E=s[t.BAD_REQUEST]){super(E,t.BAD_REQUEST,!0)}},N=class extends T{constructor(E=s[t.NOT_FOUND]){super(E,t.NOT_FOUND,!0)}},A=class extends T{constructor(E=s[t.UNAUTHORIZED]){super(E,t.UNAUTHORIZED,!0)}},I=class extends T{constructor(E=s[t.FORBIDDEN]){super(E,t.FORBIDDEN,!0)}},c=class extends T{constructor(E=s[t.CONFLICT]){super(E,t.CONFLICT,!0)}},u=class extends T{constructor(E=s[t.UNPROCESSABLE_ENTITY]){super(E,t.UNPROCESSABLE_ENTITY,!0)}},a=class extends T{constructor(E=s[t.METHOD_NOT_ALLOWED]){super(E,t.METHOD_NOT_ALLOWED,!0)}},D=class extends T{constructor(E=s[t.NOT_ACCEPTABLE]){super(E,t.NOT_ACCEPTABLE,!0)}},i=class extends T{constructor(E=s[t.REQUEST_TIMEOUT]){super(E,t.REQUEST_TIMEOUT,!0)}},S=class extends T{constructor(E=s[t.PAYLOAD_TOO_LARGE]){super(E,t.PAYLOAD_TOO_LARGE,!0)}},L=class extends T{constructor(E=s[t.UNSUPPORTED_MEDIA_TYPE]){super(E,t.UNSUPPORTED_MEDIA_TYPE,!0)}},p=class extends T{constructor(E=s[t.TOO_MANY_REQUESTS]){super(E,t.TOO_MANY_REQUESTS,!0)}},U=class extends T{constructor(E=s[t.PAYMENT_REQUIRED]){super(E,t.PAYMENT_REQUIRED,!0)}},C=class extends T{constructor(E=s[t.GONE]){super(E,t.GONE,!0)}},P=class extends T{constructor(E=s[t.PRECONDITION_FAILED]){super(E,t.PRECONDITION_FAILED,!0)}},d=class extends T{constructor(E=s[t.NOT_IMPLEMENTED]){super(E,t.NOT_IMPLEMENTED,!0)}},l=class extends T{constructor(E=s[t.BAD_GATEWAY]){super(E,t.BAD_GATEWAY,!0)}},M=class extends T{constructor(E=s[t.SERVICE_UNAVAILABLE]){super(E,t.SERVICE_UNAVAILABLE,!0)}},x=class extends T{constructor(E=s[t.GATEWAY_TIMEOUT]){super(E,t.GATEWAY_TIMEOUT,!0)}},F=class extends T{constructor(E=s[t.INSUFFICIENT_STORAGE]){super(E,t.INSUFFICIENT_STORAGE,!0)}},m=e=>e instanceof T&&e.isOparational?{status:"error",statusCode:e.statusCode,message:e.message,code:e.code}:{status:"error",statusCode:t.INTERNAL_SERVER_ERROR,message:s[t.INTERNAL_SERVER_ERROR],code:g(t.INTERNAL_SERVER_ERROR)},W=(e,E,R,O)=>{let o=m(e);R.status(o.statusCode).json({status:o.status,statusCode:o.statusCode,message:o.message,code:o.code})};var Q=(e=[])=>e[e.length-1],h=Function.prototype;function B(e,E){return Object.keys(e).forEach(R=>{E[R]=e[R]}),E}function G(e){let E=function(...O){let o=e.apply(this,O),n=(O.length===5?O[2]:Q(O))||h;return o&&o.catch&&o.catch(H=>n(H)),o};return Object.defineProperty(E,"length",{value:e.length,writable:!1}),B(e,E)}function V(){let e=Y.prototype.constructor.param;Y.prototype.constructor.param=function(R,O){return O=G(O),e.call(this,R,O)}}Object.defineProperty(y.prototype,"handle",{enumerable:!0,get(){return this.__handle},set(e){e=G(e),this.__handle=e}});V();export{T as AppError,l as BadGatewayError,_ as BadRequestError,c as ConflictError,s as DefaultStatusMessages,I as ForbiddenError,x as GatewayTimeoutError,C as GoneError,t as HttpStatusCodes,F as InsufficientStorageError,a as MethodNotAllowedError,D as NotAcceptableError,N as NotFoundError,d as NotImplementedError,S as PayloadTooLargeError,U as PaymentRequiredError,P as PreconditionFailedError,i as RequestTimeoutError,r as ServerError,M as ServiceUnavailableError,p as TooManyRequestsError,A as UnauthorizedError,u as UnprocessableEntityError,L as UnsupportedMediaTypeError,W as globalErrorHandler,m as handleError}; //# sourceMappingURL=index.mjs.map