Skip to content
Myr

HTTPError.ts

This file

Path

source/errors/HTTPError.ts

22 lines · 739 bytes · TypeScript

Last changed by

Rename some internal types and upgrade dev dependenciesSindre Sorhusbefore adoption2049aff

History of this file

Take it

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

lines 1–2why, one step back
1import type {NormalizedOptions} from '../types/options.js';
2

Rename some internal types and upgrade dev dependenciesSindre Sorhusbefore adoption2049aff

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

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

lines 4–7why, one step back
4export class HTTPError extends Error {
5 public response: Response;6 public request: Request;7 public options: NormalizedOptions;

Minor tweaksSindre Sorhusbefore adoption453846e

line 8why, one step back
8

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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

Improve HTTPError messages (#333)Seth Holladaybefore adoptionca098f8

lines 10–15why, one step back
10 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';1415 super(`Request failed with ${reason}`);

Minor tweaksSindre Sorhusbefore adoption453846e

line 16why, one step back
16

Move to TypeScript (#330)Olivier Louvignesbefore adoption2d8d68a

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