forked from tkrotoff/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpError.ts
More file actions
24 lines (21 loc) · 779 Bytes
/
HttpError.ts
File metadata and controls
24 lines (21 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* An {@link Error} that wraps a {@link Response}.
*
* Thrown when the HTTP response is not OK: HTTP status in the range 200-299.
*/
// Should be named HTTPError or HttpError?
// - [XML*Http*Request](https://developer.mozilla.org/en-US/docs/Web/API)
// - Node.js uses [http](https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/)
// - Deno uses [Http](https://github.com/denoland/deno/blob/v1.5.3/cli/rt/01_errors.js#L116)
export class HttpError extends Error {
response: Response;
constructor(response: Response) {
const { status, statusText } = response;
super(
// statusText can be empty: https://stackoverflow.com/q/41632077
statusText || String(status)
);
this.name = 'HttpError';
this.response = response;
}
}