Skip to content
Myr

HTTPError.ts

This file

Path

source/errors/HTTPError.ts

24 lines · 867 bytes · TypeScript

Last changed by

Add `data` property to `HTTPError` with pre-parsed response body (#823)Sindre Sorhusbefore adoption1341f5c

History of this file

Take it

The walk stopped after 200 commits: lines older than d4fee8a point at it.

Fix typo (#403)Leon Sibefore adoptiond4fee8a

line 1why, one step back
1import type {NormalizedOptions} from '../types/options.js';

Use KyRequest and KyResponse types in errors (#610)Mark Fultonbefore adoption8e171f5

lines 2–3why, one step back
2import type {KyRequest} from '../types/request.js';
3import type {KyResponse} from '../types/response.js';

Fix typo (#403)Leon Sibefore adoptiond4fee8a

line 4why, one step back
4

Add JSON generics to `ky()` and `HTTPError` (#619)Seth Holladaybefore adoptionf76c7cd

lines 5–6why, one step back
5export class HTTPError<T = unknown> extends Error {
6 public response: KyResponse<T>;

Use KyRequest and KyResponse types in errors (#610)Mark Fultonbefore adoption8e171f5

line 7why, one step back
7 public request: KyRequest;

Fix typo (#403)Leon Sibefore adoptiond4fee8a

line 8why, one step back
8 public options: NormalizedOptions;

Add `data` property to `HTTPError` with pre-parsed response body (#823)Sindre Sorhusbefore adoption1341f5c

line 9why, one step back
9 public data: T | string | undefined;

Fix typo (#403)Leon Sibefore adoptiond4fee8a

lines 10–12why, one step back
10
11 constructor(response: Response, request: Request, options: NormalizedOptions) {12 const code = (response.status || response.status === 0) ? response.status : '';

Minor tweak (#745)Hichembefore adoptionb9df6cf

line 13why, one step back
13 const title = response.statusText ?? '';

Fix typo (#403)Leon Sibefore adoptiond4fee8a

lines 14–16why, one step back
14 const status = `${code} ${title}`.trim();
15 const reason = status ? `status code ${status}` : 'an unknown error';16

Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3

line 17why, one step back
17 super(`Request failed with ${reason}: ${request.method} ${request.url}`);

Fix typo (#403)Leon Sibefore adoptiond4fee8a

lines 18–24why, one step back
18
19 this.name = 'HTTPError';20 this.response = response;21 this.request = request;22 this.options = options;23 }24}