UNPKG

throw-http-errors

Version:

Custom errors for HTTP status codes.

25 lines (24 loc) 876 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.httpErrors = void 0; const httpErrorCodes_1 = require("./httpErrorCodes"); function createHttpError(error) { class CustomHttpError extends Error { constructor(message, code) { super(message); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } this.name = error.name; this.status = error.status; this.code = code || error.code; this.message = message || error.message; } } return { [error.name]: CustomHttpError, [error.status]: CustomHttpError, }; } const httpErrors = httpErrorCodes_1.httpErrorCodes.reduce((result, error) => Object.assign(result, createHttpError(error)), {}); exports.httpErrors = httpErrors;