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 fileTake it
Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 1why, one step back1import type {NormalizedOptions} from '../types/options.js';Use KyRequest and KyResponse types in errors (#610)Mark Fultonbefore adoption8e171f5
lines 2–3why, one step back2import type {KyRequest} from '../types/request.js';3import type {KyResponse} from '../types/response.js';Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 4why, one step back4Rename some internal types and upgrade dev dependenciesSindre Sorhusbefore adoption2049aff
line 5why, one step back5// eslint-lint-disable-next-line @typescript-eslint/naming-conventionMove to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 6why, one step back6export class HTTPError extends Error {Use KyRequest and KyResponse types in errors (#610)Mark Fultonbefore adoption8e171f5
lines 7–8why, one step back7 public response: KyResponse;8 public request: KyRequest;Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 9why, one step back9 public options: NormalizedOptions;Minor tweaksSindre Sorhusbefore adoption453846e
line 10why, one step back10Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 11why, one step back11 constructor(response: Response, request: Request, options: NormalizedOptions) {Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8
lines 12–16why, one step back12 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';16Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3
line 17why, one step back17 super(`Request failed with ${reason}: ${request.method} ${request.url}`);Minor tweaksSindre Sorhusbefore adoption453846e
line 18why, one step back18Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 19–24why, one step back19 this.name = 'HTTPError';20 this.response = response;21 this.request = request;22 this.options = options;23 }24}