UNPKG

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