UNPKG

@otterhttp/errors

Version:

http-errors for modern Node.js

171 lines (167 loc) 4.32 kB
import { OutgoingHttpHeaders } from 'node:http'; import ModuleError from 'module-error'; /** * HTTP response status codes and their associated messages. * Source: {@link STATUS_CODES} */ declare const statusMessages: { 100: string; 101: string; 102: string; 103: string; 200: string; 201: string; 202: string; 203: string; 204: string; 205: string; 206: string; 207: string; 208: string; 226: string; 300: string; 301: string; 302: string; 303: string; 304: string; 305: string; 307: string; 308: string; 400: string; 401: string; 402: string; 403: string; 404: string; 405: string; 406: string; 407: string; 408: string; 409: string; 410: string; 411: string; 412: string; 413: string; 414: string; 415: string; 416: string; 417: string; 418: string; 421: string; 422: string; 423: string; 424: string; 425: string; 426: string; 428: string; 429: string; 431: string; 451: string; 500: string; 501: string; 502: string; 503: string; 504: string; 505: string; 506: string; 507: string; 508: string; 509: string; 510: string; 511: string; }; declare enum HttpStatus { Continue = 100, SwitchingProtocols = 101, Processing = 102, EarlyHints = 103, OK = 200, Created = 201, Accepted = 202, NonAuthoritativeInformation = 203, NoContent = 204, ResetContent = 205, PartialContent = 206, MultiStatus = 207, AlreadyReported = 208, IMUsed = 226, MultipleChoices = 300, MovedPermanently = 301, Found = 302, SeeOther = 303, NotModified = 304, UseProxy = 305, TemporaryRedirect = 307, PermanentRedirect = 308, BadRequest = 400, Unauthorized = 401, PaymentRequired = 402, Forbidden = 403, NotFound = 404, MethodNotAllowed = 405, NotAcceptable = 406, ProxyAuthenticationRequired = 407, RequestTimeout = 408, Conflict = 409, Gone = 410, LengthRequired = 411, PreconditionFailed = 412, PayloadTooLarge = 413, URITooLong = 414, UnsupportedMediaType = 415, RangeNotSatisfiable = 416, ExpectationFailed = 417, IAmATeapot = 418, MisdirectedRequest = 421, UnprocessableEntity = 422, Locked = 423, FailedDependency = 424, TooEarly = 425, UpgradeRequired = 426, PreconditionRequired = 428, TooManyRequests = 429, RequestHeaderFieldsTooLarge = 431, UnavailableForLegalReasons = 451, InternalServerError = 500, NotImplemented = 501, BadGateway = 502, ServiceUnavailable = 503, GatewayTimeout = 504, HttpVersionNotSupported = 505, VariantAlsoNegotiates = 506, InsufficientStorage = 507, LoopDetected = 508, BandwidthLimitExceeded = 509, NotExtended = 510, NetworkAuthenticationRequired = 511 } type StatusCode = keyof typeof statusMessages; declare function isValidStatusCode(statusCode: unknown): statusCode is StatusCode; type ExtraLiteral = string | number | boolean | null | undefined | { [property: string]: ExtraLiteral; } | ExtraLiteral[]; type ModuleErrorOptions = ConstructorParameters<typeof ModuleError>[1]; type HttpErrorOptions = ModuleErrorOptions & { statusCode?: StatusCode; statusMessage?: string; exposeMessage?: boolean; headers?: OutgoingHttpHeaders; extra?: Record<string, ExtraLiteral>; }; declare abstract class HttpError extends ModuleError { statusCode: StatusCode; statusMessage: string; exposeMessage: boolean; headers: OutgoingHttpHeaders; extra: Record<string, ExtraLiteral>; protected constructor(message?: string, options?: HttpErrorOptions); } declare class NotModifiedError extends HttpError { constructor(message?: string, options?: Omit<HttpErrorOptions, "statusCode">); } declare class ClientError extends HttpError { constructor(message?: string, options?: HttpErrorOptions); } declare class ServerError extends HttpError { constructor(message?: string, options?: HttpErrorOptions); } export { ClientError, HttpError, type HttpErrorOptions, HttpStatus, NotModifiedError, ServerError, type StatusCode, isValidStatusCode, statusMessages };