Skip to content
Myr

HTTPError.ts

This file

Path

source/errors/HTTPError.ts

23 lines · 829 bytes · TypeScript

Last changed by

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

History of this file

Take it

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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';

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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;

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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

Minor tweaksSindre Sorhusbefore adoption453846e

line 9why, one step back
9

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

line 10why, one step back
10 constructor(response: Response, request: Request, options: NormalizedOptions) {

Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8

lines 11–15why, one step back
11 const code = (response.status || response.status === 0) ? response.status : '';
12 const title = response.statusText || '';13 const status = `${code} ${title}`.trim();14 const reason = status ? `status code ${status}` : 'an unknown error';15

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

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

Minor tweaksSindre Sorhusbefore adoption453846e

line 17why, one step back
17

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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