HTTPError.ts
This file
Path
source/errors/HTTPError.ts
22 lines · 773 bytes · TypeScript
Last changed by
Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3
History of this fileTake it
Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 1–2why, one step back1import type {NormalizedOptions} from '../types/options.js';2Rename some internal types and upgrade dev dependenciesSindre Sorhusbefore adoption2049aff
line 3why, one step back3// eslint-lint-disable-next-line @typescript-eslint/naming-conventionMove to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 4–7why, one step back4export class HTTPError extends Error {5 public response: Response;6 public request: Request;7 public options: NormalizedOptions;Minor tweaksSindre Sorhusbefore adoption453846e
line 8why, one step back8Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 9why, one step back9 constructor(response: Response, request: Request, options: NormalizedOptions) {Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8
lines 10–14why, one step back10 const code = (response.status || response.status === 0) ? response.status : '';11 const title = response.statusText || '';12 const status = `${code} ${title}`.trim();13 const reason = status ? `status code ${status}` : 'an unknown error';14Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3
line 15why, one step back15 super(`Request failed with ${reason}: ${request.method} ${request.url}`);Minor tweaksSindre Sorhusbefore adoption453846e
line 16why, one step back16Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 17–22why, one step back17 this.name = 'HTTPError';18 this.response = response;19 this.request = request;20 this.options = options;21 }22}