UNPKG

1.35 kBTypeScriptView Raw
1/**
2 * HttpError extends the Error object, and is thrown wheenever servers emit
3 * HTTP errors.
4 *
5 * It has a response property, allowing users to find out more about the
6 * nature of the error.
7 *
8 * @constructor
9 * @param {Response} response
10 */
11export declare class HttpError extends Error {
12 response: Response;
13 status: number;
14 constructor(response: Response);
15}
16/**
17 * Problem extends the HttpError object. If a server emits a HTTP error, and
18 * the response body's content-type is application/problem+json.
19 *
20 * application/problem+json is defined in RFC7807 and provides a standardized
21 * way to describe error conditions by a HTTP server.
22 *
23 * @constructor
24 * @param {Response} response
25 * @param {object} problemBody
26 */
27export declare class Problem extends HttpError {
28 body: {
29 title?: string;
30 };
31 constructor(response: Response, problemBody: object);
32}
33/**
34 * This function creates problems, not unlike the the author of this file.
35 *
36 * It takes a Fetch Response object, and returns a HttpError. If the HTTP
37 * response has a type of application/problem+json it will return a Problem
38 * object.
39 *
40 * Because parsing the response might be asynchronous, the function returns
41 * a Promise resolving in either object.
42 */
43export default function problemFactory(response: Response): Promise<HttpError | Problem>;