UNPKG

3.95 kBTypeScriptView Raw
1export = createHttpError;
2
3declare const createHttpError: createHttpError.CreateHttpError & createHttpError.NamedConstructors & {
4 isHttpError: createHttpError.IsHttpError;
5};
6
7declare namespace createHttpError {
8 interface HttpError<N extends number = number> extends Error {
9 status: N;
10 statusCode: N;
11 expose: boolean;
12 headers?: {
13 [key: string]: string;
14 } | undefined;
15 [key: string]: any;
16 }
17
18 type UnknownError = Error | string | { [key: string]: any };
19
20 interface HttpErrorConstructor<N extends number = number> {
21 (msg?: string): HttpError<N>;
22 new(msg?: string): HttpError<N>;
23 }
24
25 interface CreateHttpError {
26 <N extends number = number>(arg: N, ...rest: UnknownError[]): HttpError<N>;
27 (...rest: UnknownError[]): HttpError;
28 }
29
30 type IsHttpError = (error: unknown) => error is HttpError;
31
32 type NamedConstructors =
33 & {
34 HttpError: HttpErrorConstructor;
35 }
36 & Record<"BadRequest" | "400", HttpErrorConstructor<400>>
37 & Record<"Unauthorized" | "401", HttpErrorConstructor<401>>
38 & Record<"PaymentRequired" | "402", HttpErrorConstructor<402>>
39 & Record<"Forbidden" | "403", HttpErrorConstructor<403>>
40 & Record<"NotFound" | "404", HttpErrorConstructor<404>>
41 & Record<"MethodNotAllowed" | "405", HttpErrorConstructor<405>>
42 & Record<"NotAcceptable" | "406", HttpErrorConstructor<406>>
43 & Record<"ProxyAuthenticationRequired" | "407", HttpErrorConstructor<407>>
44 & Record<"RequestTimeout" | "408", HttpErrorConstructor<408>>
45 & Record<"Conflict" | "409", HttpErrorConstructor<409>>
46 & Record<"Gone" | "410", HttpErrorConstructor<410>>
47 & Record<"LengthRequired" | "411", HttpErrorConstructor<411>>
48 & Record<"PreconditionFailed" | "412", HttpErrorConstructor<412>>
49 & Record<"PayloadTooLarge" | "413", HttpErrorConstructor<413>>
50 & Record<"URITooLong" | "414", HttpErrorConstructor<414>>
51 & Record<"UnsupportedMediaType" | "415", HttpErrorConstructor<415>>
52 & Record<"RangeNotSatisfiable" | "416", HttpErrorConstructor<416>>
53 & Record<"ExpectationFailed" | "417", HttpErrorConstructor<417>>
54 & Record<"ImATeapot" | "418", HttpErrorConstructor<418>>
55 & Record<"MisdirectedRequest" | "421", HttpErrorConstructor<421>>
56 & Record<"UnprocessableEntity" | "422", HttpErrorConstructor<422>>
57 & Record<"Locked" | "423", HttpErrorConstructor<423>>
58 & Record<"FailedDependency" | "424", HttpErrorConstructor<424>>
59 & Record<"TooEarly" | "425", HttpErrorConstructor<425>>
60 & Record<"UpgradeRequired" | "426", HttpErrorConstructor<426>>
61 & Record<"PreconditionRequired" | "428", HttpErrorConstructor<428>>
62 & Record<"TooManyRequests" | "429", HttpErrorConstructor<429>>
63 & Record<"RequestHeaderFieldsTooLarge" | "431", HttpErrorConstructor<431>>
64 & Record<"UnavailableForLegalReasons" | "451", HttpErrorConstructor<451>>
65 & Record<"InternalServerError" | "500", HttpErrorConstructor<500>>
66 & Record<"NotImplemented" | "501", HttpErrorConstructor<501>>
67 & Record<"BadGateway" | "502", HttpErrorConstructor<502>>
68 & Record<"ServiceUnavailable" | "503", HttpErrorConstructor<503>>
69 & Record<"GatewayTimeout" | "504", HttpErrorConstructor<504>>
70 & Record<"HTTPVersionNotSupported" | "505", HttpErrorConstructor<505>>
71 & Record<"VariantAlsoNegotiates" | "506", HttpErrorConstructor<506>>
72 & Record<"InsufficientStorage" | "507", HttpErrorConstructor<507>>
73 & Record<"LoopDetected" | "508", HttpErrorConstructor<508>>
74 & Record<"BandwidthLimitExceeded" | "509", HttpErrorConstructor<509>>
75 & Record<"NotExtended" | "510", HttpErrorConstructor<510>>
76 & Record<"NetworkAuthenticationRequire" | "511", HttpErrorConstructor<511>>;
77}