Skip to content
Myr

HTTPError.ts

This file

Path

source/errors/HTTPError.ts

24 lines · 883 bytes · TypeScript

Last changed by

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

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

Rename some internal types and upgrade dev dependenciesSindre Sorhusbefore adoption2049aff

line 5why, one step back
5// eslint-lint-disable-next-line @typescript-eslint/naming-convention

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

line 6why, one step back
6export class HTTPError extends Error {

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

lines 7–8why, one step back
7 public response: KyResponse;
8 public request: KyRequest;

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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

Minor tweaksSindre Sorhusbefore adoption453846e

line 10why, one step back
10

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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

Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8

lines 12–16why, one step back
12 const code = (response.status || response.status === 0) ? response.status : '';
13 const title = response.statusText || '';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}`);

Minor tweaksSindre Sorhusbefore adoption453846e

line 18why, one step back
18

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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