1 | // Type definitions for boom 7.3
|
2 | // Project: https://github.com/hapijs/boom
|
3 | // Definitions by: AJP <https://github.com/AJamesPhillips>
|
4 | // Jinesh Shah <https://github.com/jineshshah36>
|
5 | // Timon van Spronsen <https://github.com/TimonVS>
|
6 | // Daniel Machado <https://github.com/danielmachado>
|
7 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
8 | // TypeScript Version: 2.4
|
9 |
|
10 | export = Boom;
|
11 | /**
|
12 | * boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties:
|
13 | * @see {@link https://github.com/hapijs/boom#boom}
|
14 | */
|
15 | declare class Boom<Data = any> extends Error {
|
16 | /** Creates a new Boom object using the provided message and then calling boomify() to decorate the error with the Boom properties. */
|
17 | constructor(message?: string | Error, options?: Boom.Options<Data>);
|
18 | /** isBoom - if true, indicates this is a Boom object instance. */
|
19 | isBoom: boolean;
|
20 | /** isServer - convenience bool indicating status code >= 500. */
|
21 | isServer: boolean;
|
22 | /** message - the error message. */
|
23 | message: string;
|
24 | /** output - the formatted response. Can be directly manipulated after object construction to return a custom error response. Allowed root keys: */
|
25 | output: Boom.Output;
|
26 | /** typeof - the constructor used to create the error (e.g. Boom.badRequest). */
|
27 | readonly typeof: () => any;
|
28 | /** reformat() - rebuilds error.output using the other object properties. */
|
29 | reformat(): string;
|
30 | /**
|
31 | * "If message is unset, the 'error' segment of the header will not be present and
|
32 | * isMissing will be true on the error object." mentioned in
|
33 | * @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
34 | */
|
35 | isMissing?: boolean | undefined;
|
36 | /** https://github.com/hapijs/boom#createstatuscode-message-data and https://github.com/hapijs/boom/blob/v4.3.0/lib/index.js#L99 */
|
37 | data: Data;
|
38 | }
|
39 | declare namespace Boom {
|
40 | interface Options<Data> {
|
41 | /** statusCode - the HTTP status code. Defaults to 500 if no status code is already set. */
|
42 | statusCode?: number | undefined;
|
43 | /** data - additional error information (assigned to error.data). */
|
44 | data?: Data | undefined;
|
45 | /** decorate - an option with extra properties to set on the error object. */
|
46 | decorate?: object | undefined;
|
47 | /** ctor - constructor reference used to crop the exception call stack output. */
|
48 | ctor?: any;
|
49 | /** message - error message string. If the error already has a message, the provided message is added as a prefix. Defaults to no message. */
|
50 | message?: string | undefined;
|
51 | /**
|
52 | * override - if false, the err provided is a Boom object, and a statusCode or message are
|
53 | * provided, the values are ignored. Defaults to true (apply the provided statusCode and
|
54 | * message options to the error regardless of its type, Error or Boom object).
|
55 | */
|
56 | override?: boolean | undefined;
|
57 | }
|
58 |
|
59 | interface Output {
|
60 | /** statusCode - the HTTP status code (typically 4xx or 5xx). */
|
61 | statusCode: number;
|
62 | /**
|
63 | * headers - an object containing any HTTP headers where each key is a header name and
|
64 | * value is the header content. (Limited value type to string
|
65 | * https://github.com/hapijs/boom/issues/151 )
|
66 | */
|
67 | headers: { [index: string]: string };
|
68 | /**
|
69 | * payload - the formatted object used as the response payload (stringified).
|
70 | * Can be directly manipulated but any changes will be lost if reformat() is called.
|
71 | * Any content allowed and by default includes the following content:
|
72 | */
|
73 | payload: Payload;
|
74 | }
|
75 |
|
76 | interface Payload {
|
77 | /** statusCode - the HTTP status code, derived from error.output.statusCode. */
|
78 | statusCode: number;
|
79 | /** error - the HTTP status message (e.g. 'Bad Request', 'Internal Server Error') derived from statusCode. */
|
80 | error: string;
|
81 | /** message - the error message derived from error.message. */
|
82 | message: string;
|
83 | /**
|
84 | * "Every key/value pair will be included ... in the response payload under the attributes key."
|
85 | * [see docs](https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes)
|
86 | */
|
87 | attributes?: any;
|
88 | // Excluded this to aid typing of the other values. See tests for example casting to a custom interface to manipulate the payload
|
89 | // [anyContent: string]: any;
|
90 | }
|
91 |
|
92 | /**
|
93 | * Decorates an error with the boom properties
|
94 | * @param error the error object to wrap. If error is already a boom object, it defaults to overriding the object with the new status code and message.
|
95 | * @param options optional additional options
|
96 | * @see {@link https://github.com/hapijs/boom#boomifyerror-options}
|
97 | */
|
98 | function boomify(
|
99 | error: Error,
|
100 | options?: { statusCode?: number | undefined; message?: string | undefined; override?: boolean | undefined },
|
101 | ): Boom<null>;
|
102 |
|
103 | /**
|
104 | * Identifies whether an error is a Boom object. Same as calling instanceof Boom.
|
105 | * @param error the error object to identify.
|
106 | */
|
107 | function isBoom(error: Error): error is Boom;
|
108 |
|
109 | // 4xx
|
110 | /**
|
111 | * Returns a 400 Bad Request error
|
112 | * @param message optional message.
|
113 | * @param data optional additional error data.
|
114 | * @see {@link https://github.com/hapijs/boom#boombadrequestmessage-data}
|
115 | */
|
116 | function badRequest<Data = null>(message?: string, data?: Data): Boom<Data>;
|
117 |
|
118 | /**
|
119 | * Returns a 401 Unauthorized error
|
120 | * @param message optional message.
|
121 | * @param scheme can be one of the following:
|
122 | * * an authentication scheme name
|
123 | * * an array of string values. These values will be separated by ', ' and set to the 'WWW-Authenticate' header.
|
124 | * @param attributes an object of values to use while setting the 'WWW-Authenticate' header.
|
125 | * This value is only used when scheme is a string, otherwise it is ignored.
|
126 | * Every key/value pair will be included in the 'WWW-Authenticate' in the format of
|
127 | * 'key="value"' as well as in the response payload under the attributes key.
|
128 | * Alternatively value can be a string which is use to set the value of the scheme,
|
129 | * for example setting the token value for negotiate header.
|
130 | * If string is used message parameter must be null.
|
131 | * null and undefined will be replaced with an empty string. If attributes is set,
|
132 | * message will be used as the 'error' segment of the 'WWW-Authenticate' header.
|
133 | * If message is unset, the 'error' segment of the header will not be present and isMissing will be true on the error object.
|
134 | * @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
135 | */
|
136 | function unauthorized(message?: string, scheme?: string, attributes?: { [index: string]: string }): Boom<null>;
|
137 | function unauthorized(message?: string, scheme?: string[]): Boom<null>;
|
138 | function unauthorized(
|
139 | message?: null,
|
140 | scheme?: string,
|
141 | attributes?: { [index: string]: string } | string,
|
142 | ): Boom<null>;
|
143 |
|
144 | /**
|
145 | * Returns a 402 Payment Required error
|
146 | * @param message optional message.
|
147 | * @param data optional additional error data.
|
148 | * @see {@link https://github.com/hapijs/boom#boompaymentrequiredmessage-data}
|
149 | */
|
150 | function paymentRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
151 |
|
152 | /**
|
153 | * Returns a 403 Forbidden error
|
154 | * @param message optional message.
|
155 | * @param data optional additional error data.
|
156 | * @see {@link https://github.com/hapijs/boom#boomforbiddenmessage-data}
|
157 | */
|
158 | function forbidden<Data = null>(message?: string, data?: Data): Boom<Data>;
|
159 |
|
160 | /**
|
161 | * Returns a 404 Not Found error
|
162 | * @param message optional message.
|
163 | * @param data optional additional error data.
|
164 | * @see {@link https://github.com/hapijs/boom#boomnotfoundmessage-data}
|
165 | */
|
166 | function notFound<Data = null>(message?: string, data?: Data): Boom<Data>;
|
167 |
|
168 | /**
|
169 | * Returns a 405 Method Not Allowed error
|
170 | * @param message optional message.
|
171 | * @param data optional additional error data.
|
172 | * @param allow optional string or array of strings (to be combined and separated by ', ') which is set to the 'Allow' header.
|
173 | * @see {@link https://github.com/hapijs/boom#boommethodnotallowedmessage-data-allow}
|
174 | */
|
175 | function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
|
176 |
|
177 | /**
|
178 | * Returns a 406 Not Acceptable error
|
179 | * @param message optional message.
|
180 | * @param data optional additional error data.
|
181 | * @see {@link https://github.com/hapijs/boom#boomnotacceptablemessage-data}
|
182 | */
|
183 | function notAcceptable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
184 |
|
185 | /**
|
186 | * Returns a 407 Proxy Authentication Required error
|
187 | * @param message optional message.
|
188 | * @param data optional additional error data.
|
189 | * @see {@link https://github.com/hapijs/boom#boomproxyauthrequiredmessage-data}
|
190 | */
|
191 | function proxyAuthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
192 |
|
193 | /**
|
194 | * Returns a 408 Request Time-out error
|
195 | * @param message optional message.
|
196 | * @param data optional additional error data.
|
197 | * @see {@link https://github.com/hapijs/boom#boomclienttimeoutmessage-data}
|
198 | */
|
199 | function clientTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
200 |
|
201 | /**
|
202 | * Returns a 409 Conflict error
|
203 | * @param message optional message.
|
204 | * @param data optional additional error data.
|
205 | * @see {@link https://github.com/hapijs/boom#boomconflictmessage-data}
|
206 | */
|
207 | function conflict<Data = null>(message?: string, data?: Data): Boom<Data>;
|
208 |
|
209 | /**
|
210 | * Returns a 410 Gone error
|
211 | * @param message optional message.
|
212 | * @param data optional additional error data.
|
213 | * @see {@link https://github.com/hapijs/boom#boomresourcegonemessage-data}
|
214 | */
|
215 | function resourceGone<Data = null>(message?: string, data?: Data): Boom<Data>;
|
216 |
|
217 | /**
|
218 | * Returns a 411 Length Required error
|
219 | * @param message optional message.
|
220 | * @param data optional additional error data.
|
221 | * @see {@link https://github.com/hapijs/boom#boomlengthrequiredmessage-data}
|
222 | */
|
223 | function lengthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
224 |
|
225 | /**
|
226 | * Returns a 412 Precondition Failed error
|
227 | * @param message optional message.
|
228 | * @param data optional additional error data.
|
229 | * @see {@link https://github.com/hapijs/boom#boompreconditionfailedmessage-data}
|
230 | */
|
231 | function preconditionFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
232 |
|
233 | /**
|
234 | * Returns a 413 Request Entity Too Large error
|
235 | * @param message optional message.
|
236 | * @param data optional additional error data.
|
237 | * @see {@link https://github.com/hapijs/boom#boomentitytoolargemessage-data}
|
238 | */
|
239 | function entityTooLarge<Data = null>(message?: string, data?: Data): Boom<Data>;
|
240 |
|
241 | /**
|
242 | * Returns a 414 Request-URI Too Large error
|
243 | * @param message optional message.
|
244 | * @param data optional additional error data.
|
245 | * @see {@link https://github.com/hapijs/boom#boomuritoolongmessage-data}
|
246 | */
|
247 | function uriTooLong<Data = null>(message?: string, data?: Data): Boom<Data>;
|
248 |
|
249 | /**
|
250 | * Returns a 415 Unsupported Media Type error
|
251 | * @param message optional message.
|
252 | * @param data optional additional error data.
|
253 | * @see {@link https://github.com/hapijs/boom#boomunsupportedmediatypemessage-data}
|
254 | */
|
255 | function unsupportedMediaType<Data = null>(message?: string, data?: Data): Boom<Data>;
|
256 |
|
257 | /**
|
258 | * Returns a 416 Requested Range Not Satisfiable error
|
259 | * @param message optional message.
|
260 | * @param data optional additional error data.
|
261 | * @see {@link https://github.com/hapijs/boom#boomrangenotsatisfiablemessage-data}
|
262 | */
|
263 | function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
264 |
|
265 | /**
|
266 | * Returns a 417 Expectation Failed error
|
267 | * @param message optional message.
|
268 | * @param data optional additional error data.
|
269 | * @see {@link https://github.com/hapijs/boom#boomexpectationfailedmessage-data}
|
270 | */
|
271 | function expectationFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
272 |
|
273 | /**
|
274 | * Returns a 418 I'm a Teapot error
|
275 | * @param message optional message.
|
276 | * @param data optional additional error data.
|
277 | * @see {@link https://github.com/hapijs/boom#boomteapotmessage-data}
|
278 | */
|
279 | function teapot<Data = null>(message?: string, data?: Data): Boom<Data>;
|
280 |
|
281 | /**
|
282 | * Returns a 422 Unprocessable Entity error
|
283 | * @param message optional message.
|
284 | * @param data optional additional error data.
|
285 | * @see {@link https://github.com/hapijs/boom#boombaddatamessage-data}
|
286 | */
|
287 | function badData<Data = null>(message?: string, data?: Data): Boom<Data>;
|
288 |
|
289 | /**
|
290 | * Returns a 423 Locked error
|
291 | * @param message optional message.
|
292 | * @param data optional additional error data.
|
293 | * @see {@link https://github.com/hapijs/boom#boomlockedmessage-data}
|
294 | */
|
295 | function locked<Data = null>(message?: string, data?: Data): Boom<Data>;
|
296 |
|
297 | /**
|
298 | * Returns a 424 Failed Dependency error
|
299 | * @param message optional message.
|
300 | * @param data optional additional error data.
|
301 | * @see {@link https://github.com/hapijs/boom#boomfaileddependencymessage-data}
|
302 | */
|
303 | function failedDependency<Data = null>(message?: string, data?: Data): Boom<Data>;
|
304 |
|
305 | /**
|
306 | * Returns a 428 Precondition Required error
|
307 | * @param message optional message.
|
308 | * @param data optional additional error data.
|
309 | * @see {@link https://github.com/hapijs/boom#boompreconditionrequiredmessage-data}
|
310 | */
|
311 | function preconditionRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
312 |
|
313 | /**
|
314 | * Returns a 429 Too Many Requests error
|
315 | * @param message optional message.
|
316 | * @param data optional additional error data.
|
317 | * @see {@link https://github.com/hapijs/boom#boomtoomanyrequestsmessage-data}
|
318 | */
|
319 | function tooManyRequests<Data = null>(message?: string, data?: Data): Boom<Data>;
|
320 |
|
321 | /**
|
322 | * Returns a 451 Unavailable For Legal Reasons error
|
323 | * @param message optional message.
|
324 | * @param data optional additional error data.
|
325 | * @see {@link https://github.com/hapijs/boom#boomillegalmessage-data}
|
326 | */
|
327 | function illegal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
328 |
|
329 | // 5xx
|
330 | /**
|
331 | * Returns a 500 Internal Server Error error
|
332 | * Only 500 errors will hide your message from the end user. Your message is recorded in the server log.
|
333 | * @param message optional message.
|
334 | * @param data optional additional error data.
|
335 | * @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
336 | */
|
337 | function badImplementation<Data = null>(message?: string, data?: Data): Boom<Data>;
|
338 |
|
339 | /**
|
340 | * Returns a 500 Internal Server Error error
|
341 | * Only 500 errors will hide your message from the end user. Your message is recorded in the server log.
|
342 | * @param message optional message.
|
343 | * @param data optional additional error data.
|
344 | * @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
345 | */
|
346 | function internal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
347 |
|
348 | /**
|
349 | * Returns a 501 Not Implemented error with your error message to the user
|
350 | * @param message optional message.
|
351 | * @param data optional additional error data.
|
352 | * @see {@link https://github.com/hapijs/boom#boomnotimplementedmessage-data}
|
353 | */
|
354 | function notImplemented<Data = null>(message?: string, data?: Data): Boom<Data>;
|
355 |
|
356 | /**
|
357 | * Returns a 502 Bad Gateway error with your error message to the user
|
358 | * @param message optional message.
|
359 | * @param data optional additional error data.
|
360 | * @see {@link https://github.com/hapijs/boom#boombadgatewaymessage-data}
|
361 | */
|
362 | function badGateway<Data = null>(message?: string, data?: Data): Boom<Data>;
|
363 |
|
364 | /**
|
365 | * Returns a 503 Service Unavailable error with your error message to the user
|
366 | * @param message optional message.
|
367 | * @param data optional additional error data.
|
368 | * @see {@link https://github.com/hapijs/boom#boomserverunavailablemessage-data}
|
369 | */
|
370 | function serverUnavailable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
371 |
|
372 | /**
|
373 | * Returns a 504 Gateway Time-out error with your error message to the user
|
374 | * @param message optional message.
|
375 | * @param data optional additional error data.
|
376 | * @see {@link https://github.com/hapijs/boom#boomgatewaytimeoutmessage-data}
|
377 | */
|
378 | function gatewayTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
379 | }
|