forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httperr.d.ts
292 lines (263 loc) · 10.4 KB
/
httperr.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Type definitions for httperr v1.0.0
// Project: https://github.com/pluma/httperr
// Definitions by: Troy Gerwien <https://github.com/yortus>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "httperr" {
/** Overall module shape, expressed as an interface. */
interface HttpErr {
/** The base type for all httperr error types. You probably don't want to use this directly. */
HttpError: HttpErrorStatic;
/**
* Creates a new error type for the given HTTP error status.
* @param {number} status - The HTTP response status code for the HTTP error.
* @param {string} title - A human-readable title for the HTTP error.
* @param {Function} init - (optional) A function which will be invoked as a method of the
* new error with the config argument immediately after the error
* is created by the factory. Can be used to process additional
* error-specific configuration parameters.
*/
createHttpError(status: number, title: string, init?: (config: Config) => void): HttpErrorStatic;
// Error builders by camel-cased name.
badRequest: ErrorBuilder;
unauthorized: ErrorBuilder;
paymentRequired: ErrorBuilder;
forbidden: ErrorBuilder;
notFound: ErrorBuilder;
methodNotAllowed: ErrorBuilder;
notAcceptable: ErrorBuilder;
proxyAuthenticationRequired: ErrorBuilder;
requestTimeout: ErrorBuilder;
conflict: ErrorBuilder;
gone: ErrorBuilder;
lengthRequired: ErrorBuilder;
preconditionFailed: ErrorBuilder;
requestEntityTooLarge: ErrorBuilder;
requestUriTooLong: ErrorBuilder;
unsupportedMediaType: ErrorBuilder;
requestedRangeNotSatisfiable: ErrorBuilder;
expectationFailed: ErrorBuilder;
imATeapot: ErrorBuilder;
authenticationTimeout: ErrorBuilder;
enhanceYourCalm: ErrorBuilder;
unprocessableEntity: ErrorBuilder;
locked: ErrorBuilder;
methodFailure: ErrorBuilder;
failedDependency: ErrorBuilder;
unorderedCollection: ErrorBuilder;
upgradeRequired: ErrorBuilder;
preconditionRequired: ErrorBuilder;
tooManyRequests: ErrorBuilder;
requestHeaderFieldsTooLarge: ErrorBuilder;
loginTimeout: ErrorBuilder;
noResponse: ErrorBuilder;
retryWith: ErrorBuilder;
blockedByWindowsParentalControls: ErrorBuilder;
redirect: ErrorBuilder;
unavailableForLegalReasons: ErrorBuilder;
requestHeaderTooLarge: ErrorBuilder;
certError: ErrorBuilder;
noCert: ErrorBuilder;
httpToHttps: ErrorBuilder;
clientClosedRequest: ErrorBuilder;
internalServerError: ErrorBuilder;
notImplemented: ErrorBuilder;
badGateway: ErrorBuilder;
serviceUnavailable: ErrorBuilder;
gatewayTimeout: ErrorBuilder;
httpVersionNotSupported: ErrorBuilder;
variantAlsoNegotiates: ErrorBuilder;
insufficientStorage: ErrorBuilder;
loopDetected: ErrorBuilder;
bandwidthLimitExceeded: ErrorBuilder;
notExtended: ErrorBuilder;
networkAuthenticationRequired: ErrorBuilder;
originError: ErrorBuilder;
connectionTimedOut: ErrorBuilder;
proxyDeclinedRequest: ErrorBuilder;
aTimeoutOccured: ErrorBuilder;
networkReadTimeoutError: ErrorBuilder;
networkConnectTimeoutError: ErrorBuilder;
// Error builders by title-cased name.
BadRequest: ErrorBuilder;
Unauthorized: ErrorBuilder;
PaymentRequired: ErrorBuilder;
Forbidden: ErrorBuilder;
NotFound: ErrorBuilder;
MethodNotAllowed: ErrorBuilder;
NotAcceptable: ErrorBuilder;
ProxyAuthenticationRequired: ErrorBuilder;
RequestTimeout: ErrorBuilder;
Conflict: ErrorBuilder;
Gone: ErrorBuilder;
LengthRequired: ErrorBuilder;
PreconditionFailed: ErrorBuilder;
RequestEntityTooLarge: ErrorBuilder;
RequestUriTooLong: ErrorBuilder;
UnsupportedMediaType: ErrorBuilder;
RequestedRangeNotSatisfiable: ErrorBuilder;
ExpectationFailed: ErrorBuilder;
ImATeapot: ErrorBuilder;
AuthenticationTimeout: ErrorBuilder;
EnhanceYourCalm: ErrorBuilder;
UnprocessableEntity: ErrorBuilder;
Locked: ErrorBuilder;
MethodFailure: ErrorBuilder;
FailedDependency: ErrorBuilder;
UnorderedCollection: ErrorBuilder;
UpgradeRequired: ErrorBuilder;
PreconditionRequired: ErrorBuilder;
TooManyRequests: ErrorBuilder;
RequestHeaderFieldsTooLarge: ErrorBuilder;
LoginTimeout: ErrorBuilder;
NoResponse: ErrorBuilder;
RetryWith: ErrorBuilder;
BlockedByWindowsParentalControls: ErrorBuilder;
Redirect: ErrorBuilder;
UnavailableForLegalReasons: ErrorBuilder;
RequestHeaderTooLarge: ErrorBuilder;
CertError: ErrorBuilder;
NoCert: ErrorBuilder;
HttpToHttps: ErrorBuilder;
ClientClosedRequest: ErrorBuilder;
InternalServerError: ErrorBuilder;
NotImplemented: ErrorBuilder;
BadGateway: ErrorBuilder;
ServiceUnavailable: ErrorBuilder;
GatewayTimeout: ErrorBuilder;
HttpVersionNotSupported: ErrorBuilder;
VariantAlsoNegotiates: ErrorBuilder;
InsufficientStorage: ErrorBuilder;
LoopDetected: ErrorBuilder;
BandwidthLimitExceeded: ErrorBuilder;
NotExtended: ErrorBuilder;
NetworkAuthenticationRequired: ErrorBuilder;
OriginError: ErrorBuilder;
ConnectionTimedOut: ErrorBuilder;
ProxyDeclinedRequest: ErrorBuilder;
ATimeoutOccured: ErrorBuilder;
NetworkReadTimeoutError: ErrorBuilder;
NetworkConnectTimeoutError: ErrorBuilder;
// Error builders by statusCode.
400: ErrorBuilder;
401: ErrorBuilder;
402: ErrorBuilder;
403: ErrorBuilder;
404: ErrorBuilder;
405: ErrorBuilder;
406: ErrorBuilder;
407: ErrorBuilder;
408: ErrorBuilder;
409: ErrorBuilder;
410: ErrorBuilder;
411: ErrorBuilder;
412: ErrorBuilder;
413: ErrorBuilder;
414: ErrorBuilder;
415: ErrorBuilder;
416: ErrorBuilder;
417: ErrorBuilder;
418: ErrorBuilder;
419: ErrorBuilder;
420: ErrorBuilder;
422: ErrorBuilder;
423: ErrorBuilder;
424: ErrorBuilder;
425: ErrorBuilder;
426: ErrorBuilder;
428: ErrorBuilder;
429: ErrorBuilder;
431: ErrorBuilder;
440: ErrorBuilder;
444: ErrorBuilder;
449: ErrorBuilder;
450: ErrorBuilder;
451: ErrorBuilder;
494: ErrorBuilder;
495: ErrorBuilder;
496: ErrorBuilder;
497: ErrorBuilder;
499: ErrorBuilder;
500: ErrorBuilder;
501: ErrorBuilder;
502: ErrorBuilder;
503: ErrorBuilder;
504: ErrorBuilder;
505: ErrorBuilder;
506: ErrorBuilder;
507: ErrorBuilder;
508: ErrorBuilder;
509: ErrorBuilder;
510: ErrorBuilder;
511: ErrorBuilder;
520: ErrorBuilder;
522: ErrorBuilder;
523: ErrorBuilder;
524: ErrorBuilder;
598: ErrorBuilder;
599: ErrorBuilder;
}
/** Constructor function for the HttpError class. */
interface HttpErrorStatic {
new(config?: string | Error | Config, extra?: {}): HttpError;
}
/** An instance of the HttpError class. */
interface HttpError extends Error {
/** A human-readable title for the HTTP error. */
title: string;
code: string;
/** The HTTP response status code for the HTTP error. */
statusCode: number;
toObject(...skip: (string|RegExp)[]): any;
}
/** Configuration object for constructing HttpErrors. */
interface Config {
/** A descriptive human-readable title describing the error's cause. */
message?: string;
/** The underlying exception that caused the HTTP error. */
cause?: Error;
/** A detailed human-readable description of the error's cause and possible solutions. */
details?: string;
/**
* The methods allowed for this URL.
* This property is only available for 405 Method Not Allowed errors
* and can be used to populate the Allow header.
*/
allowed?: string[];
/**
* The minimum delay before the request should be attempted again.
* This property is only available for 429 Too Many Requests and 420 Enhance Your Calm
* (Twitter API) errors and can be used to populate the Retry-After header.
*/
retryAfter?: any;
/**
* The parameters with which the request should be retried.
* This property is only available for 449 Retry With (Microsoft) errors and can be
* used to populate the response status message.
*/
parameters?: any;
/**
* The location for which the request should be repeated.
* This property is only available for 451 Redirect (Microsoft) errors and can be
* used to populate the proprietary X-MS-Location response header.
*/
location?: any;
}
/** Factory function for creating an Error object. */
interface ErrorBuilder {
/**
* Creates an Error object. The new keyword is optional.
* @param {string | Error | Config} config - If config is a string, it will be treated as config.message.
* If config is an Error object, it will be treated as config.cause.
*/
(config?: string | Error | Config): HttpError;
/**
* Creates an Error object. The new keyword is optional.
* @param {string | Error | Config} config - If config is a string, it will be treated as config.message.
* If config is an Error object, it will be treated as config.cause.
*/
new (config?: string | Error | Config): HttpError;
}
// The module value satisfies the HttpErr interface.
var _: HttpErr;
export = _;
}