HTTPError.ts
This file
Path
source/errors/HTTPError.ts
21 lines · 669 bytes · TypeScript
Last changed by
Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8
History of this fileTake it
Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 1–6why, one step back1import type {NormalizedOptions} from '../types/options.js';23export class HTTPError extends Error {4 public response: Response;5 public request: Request;6 public options: NormalizedOptions;Minor tweaksSindre Sorhusbefore adoption453846e
line 7why, one step back7Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
line 8why, one step back8 constructor(response: Response, request: Request, options: NormalizedOptions) {Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8
lines 9–14why, one step back9 const code = (response.status || response.status === 0) ? response.status : '';10 const title = response.statusText || '';11 const status = `${code} ${title}`.trim();12 const reason = status ? `status code ${status}` : 'an unknown error';1314 super(`Request failed with ${reason}`);Minor tweaksSindre Sorhusbefore adoption453846e
line 15why, one step back15Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a
lines 16–21why, one step back16 this.name = 'HTTPError';17 this.response = response;18 this.request = request;19 this.options = options;20 }21}