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 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 back4Add JSON generics to `ky()` and `HTTPError` (#619)Seth Holladaybefore adoptionf76c7cd
lines 5–6why, one step back5export 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 back7 public request: KyRequest;Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 8why, one step back8 public options: NormalizedOptions;Minor tweaksSindre Sorhusbefore adoption453846e
line 9why, one step back9Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 10why, one step back10 constructor(response: Response, request: Request, options: NormalizedOptions) {Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8
lines 11–15why, one step back11 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';15Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3
line 16why, one step back16 super(`Request failed with ${reason}: ${request.method} ${request.url}`);Minor tweaksSindre Sorhusbefore adoption453846e
line 17why, one step back17Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 18–23why, one step back18 this.name = 'HTTPError';19 this.response = response;20 this.request = request;21 this.options = options;22 }23}