HTTPError.ts
This file
Path
source/errors/HTTPError.ts
30 lines · 1.2 KiB · TypeScript
Last changed by
Add `NetworkError` class and tighten retry logic (#842)Sindre Sorhusbefore adoptioneaf0b80
History of this fileTake it
The walk stopped after 200 commits: lines older than f34fb1f point at it.
Fix response details getting lost when using `onDownloadProgress` (#441)Yixuan Xubefore adoptionf34fb1f
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';Make `beforeError` hook receive all errors (#829)Sindre Sorhusbefore adoption101c74b
line 4why, one step back4import {KyError} from './KyError.js';Fix response details getting lost when using `onDownloadProgress` (#441)Yixuan Xubefore adoptionf34fb1f
line 5why, one step back5TweaksSindre Sorhusbefore adoption191057d
lines 6–8why, one step back6/**7Error thrown when the response has a non-2xx status code and `throwHttpErrors` is enabled.8Add `NetworkError` class and tighten retry logic (#842)Sindre Sorhusbefore adoptioneaf0b80
line 9why, one step back9The error has a `response` property with the `Response` object, a `request` property with the `Request` object, an `options` property with the normalized options, and a `data` property with the pre-parsed response body.TweaksSindre Sorhusbefore adoption191057d
line 10why, one step back10*/Make `beforeError` hook receive all errors (#829)Sindre Sorhusbefore adoption101c74b
lines 11–16why, one step back11export class HTTPError<T = unknown> extends KyError {12 override name = 'HTTPError' as const;13 response: KyResponse<T>;14 request: KyRequest;15 options: NormalizedOptions;16 data: T | string | undefined;Fix response details getting lost when using `onDownloadProgress` (#441)Yixuan Xubefore adoptionf34fb1f
lines 17–19why, one step back1718 constructor(response: Response, request: Request, options: NormalizedOptions) {19 const code = (response.status || response.status === 0) ? response.status : '';Minor tweak (#745)Hichembefore adoptionb9df6cf
line 20why, one step back20 const title = response.statusText ?? '';Fix response details getting lost when using `onDownloadProgress` (#441)Yixuan Xubefore adoptionf34fb1f
lines 21–23why, one step back21 const status = `${code} ${title}`.trim();22 const reason = status ? `status code ${status}` : 'an unknown error';23Add request method and URL to error messages (#595)Seth Holladaybefore adoption36d0bd3
line 24why, one step back24 super(`Request failed with ${reason}: ${request.method} ${request.url}`);Fix response details getting lost when using `onDownloadProgress` (#441)Yixuan Xubefore adoptionf34fb1f
lines 25–30why, one step back2526 this.response = response;27 this.request = request;28 this.options = options;29 }30}