|
| 1 | +"use strict"; |
| 2 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 3 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 4 | +}; |
| 5 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 6 | +const http_errors_1 = __importDefault(require("http-errors")); |
| 7 | +const properties_1 = require("./properties"); |
| 8 | +class ExtendedHttpError extends Error { |
| 9 | + constructor(message, properties) { |
| 10 | + super(''); |
| 11 | + // Normalize arguments |
| 12 | + if (typeof message === 'object') { |
| 13 | + properties = message; |
| 14 | + message = undefined; |
| 15 | + } |
| 16 | + // Create a http-error with the same name and get its properties |
| 17 | + const standardError = new http_errors_1.default[this.constructor.name](message); |
| 18 | + const { status, statusCode, message: msg, headers, expose, stack } = standardError; |
| 19 | + // Assign properties - Use explicit assignment to avoid TS warning |
| 20 | + this.status = status; |
| 21 | + this.statusCode = statusCode; |
| 22 | + this.message = msg; |
| 23 | + this.headers = headers; |
| 24 | + this.expose = expose; |
| 25 | + this.stack = stack; |
| 26 | + // Assign additional properties |
| 27 | + if (properties) { |
| 28 | + properties_1.addAdditionalProperties(this, properties); |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +exports.ExtendedHttpError = ExtendedHttpError; |
| 33 | +// Keep these in sync with https://www.npmjs.com/package/http-errors |
| 34 | +class BadRequest extends ExtendedHttpError { |
| 35 | +} |
| 36 | +exports.BadRequest = BadRequest; |
| 37 | +class Unauthorized extends ExtendedHttpError { |
| 38 | +} |
| 39 | +exports.Unauthorized = Unauthorized; |
| 40 | +class PaymentRequired extends ExtendedHttpError { |
| 41 | +} |
| 42 | +exports.PaymentRequired = PaymentRequired; |
| 43 | +class Forbidden extends ExtendedHttpError { |
| 44 | +} |
| 45 | +exports.Forbidden = Forbidden; |
| 46 | +class NotFound extends ExtendedHttpError { |
| 47 | +} |
| 48 | +exports.NotFound = NotFound; |
| 49 | +class MethodNotAllowed extends ExtendedHttpError { |
| 50 | +} |
| 51 | +exports.MethodNotAllowed = MethodNotAllowed; |
| 52 | +class NotAcceptable extends ExtendedHttpError { |
| 53 | +} |
| 54 | +exports.NotAcceptable = NotAcceptable; |
| 55 | +class ProxyAuthenticationRequired extends ExtendedHttpError { |
| 56 | +} |
| 57 | +exports.ProxyAuthenticationRequired = ProxyAuthenticationRequired; |
| 58 | +class RequestTimeout extends ExtendedHttpError { |
| 59 | +} |
| 60 | +exports.RequestTimeout = RequestTimeout; |
| 61 | +class Conflict extends ExtendedHttpError { |
| 62 | +} |
| 63 | +exports.Conflict = Conflict; |
| 64 | +class Gone extends ExtendedHttpError { |
| 65 | +} |
| 66 | +exports.Gone = Gone; |
| 67 | +class LengthRequired extends ExtendedHttpError { |
| 68 | +} |
| 69 | +exports.LengthRequired = LengthRequired; |
| 70 | +class PreconditionFailed extends ExtendedHttpError { |
| 71 | +} |
| 72 | +exports.PreconditionFailed = PreconditionFailed; |
| 73 | +class PayloadTooLarge extends ExtendedHttpError { |
| 74 | +} |
| 75 | +exports.PayloadTooLarge = PayloadTooLarge; |
| 76 | +class URITooLong extends ExtendedHttpError { |
| 77 | +} |
| 78 | +exports.URITooLong = URITooLong; |
| 79 | +class UnsupportedMediaType extends ExtendedHttpError { |
| 80 | +} |
| 81 | +exports.UnsupportedMediaType = UnsupportedMediaType; |
| 82 | +class RangeNotSatisfiable extends ExtendedHttpError { |
| 83 | +} |
| 84 | +exports.RangeNotSatisfiable = RangeNotSatisfiable; |
| 85 | +class ExpectationFailed extends ExtendedHttpError { |
| 86 | +} |
| 87 | +exports.ExpectationFailed = ExpectationFailed; |
| 88 | +class ImATeapot extends ExtendedHttpError { |
| 89 | +} |
| 90 | +exports.ImATeapot = ImATeapot; |
| 91 | +class MisdirectedRequest extends ExtendedHttpError { |
| 92 | +} |
| 93 | +exports.MisdirectedRequest = MisdirectedRequest; |
| 94 | +class UnprocessableEntity extends ExtendedHttpError { |
| 95 | +} |
| 96 | +exports.UnprocessableEntity = UnprocessableEntity; |
| 97 | +class Locked extends ExtendedHttpError { |
| 98 | +} |
| 99 | +exports.Locked = Locked; |
| 100 | +class FailedDependency extends ExtendedHttpError { |
| 101 | +} |
| 102 | +exports.FailedDependency = FailedDependency; |
| 103 | +class UnorderedCollection extends ExtendedHttpError { |
| 104 | +} |
| 105 | +exports.UnorderedCollection = UnorderedCollection; |
| 106 | +class UpgradeRequired extends ExtendedHttpError { |
| 107 | +} |
| 108 | +exports.UpgradeRequired = UpgradeRequired; |
| 109 | +class PreconditionRequired extends ExtendedHttpError { |
| 110 | +} |
| 111 | +exports.PreconditionRequired = PreconditionRequired; |
| 112 | +class TooManyRequests extends ExtendedHttpError { |
| 113 | +} |
| 114 | +exports.TooManyRequests = TooManyRequests; |
| 115 | +class RequestHeaderFieldsTooLarge extends ExtendedHttpError { |
| 116 | +} |
| 117 | +exports.RequestHeaderFieldsTooLarge = RequestHeaderFieldsTooLarge; |
| 118 | +class UnavailableForLegalReasons extends ExtendedHttpError { |
| 119 | +} |
| 120 | +exports.UnavailableForLegalReasons = UnavailableForLegalReasons; |
| 121 | +class InternalServerError extends ExtendedHttpError { |
| 122 | +} |
| 123 | +exports.InternalServerError = InternalServerError; |
| 124 | +class NotImplemented extends ExtendedHttpError { |
| 125 | +} |
| 126 | +exports.NotImplemented = NotImplemented; |
| 127 | +class BadGateway extends ExtendedHttpError { |
| 128 | +} |
| 129 | +exports.BadGateway = BadGateway; |
| 130 | +class ServiceUnavailable extends ExtendedHttpError { |
| 131 | +} |
| 132 | +exports.ServiceUnavailable = ServiceUnavailable; |
| 133 | +class GatewayTimeout extends ExtendedHttpError { |
| 134 | +} |
| 135 | +exports.GatewayTimeout = GatewayTimeout; |
| 136 | +class HTTPVersionNotSupported extends ExtendedHttpError { |
| 137 | +} |
| 138 | +exports.HTTPVersionNotSupported = HTTPVersionNotSupported; |
| 139 | +class VariantAlsoNegotiates extends ExtendedHttpError { |
| 140 | +} |
| 141 | +exports.VariantAlsoNegotiates = VariantAlsoNegotiates; |
| 142 | +class InsufficientStorage extends ExtendedHttpError { |
| 143 | +} |
| 144 | +exports.InsufficientStorage = InsufficientStorage; |
| 145 | +class LoopDetected extends ExtendedHttpError { |
| 146 | +} |
| 147 | +exports.LoopDetected = LoopDetected; |
| 148 | +class BandwidthLimitExceeded extends ExtendedHttpError { |
| 149 | +} |
| 150 | +exports.BandwidthLimitExceeded = BandwidthLimitExceeded; |
| 151 | +class NotExtended extends ExtendedHttpError { |
| 152 | +} |
| 153 | +exports.NotExtended = NotExtended; |
| 154 | +class NetworkAuthenticationRequire extends ExtendedHttpError { |
| 155 | +} |
| 156 | +exports.NetworkAuthenticationRequire = NetworkAuthenticationRequire; |
0 commit comments