Skip to content
Myr

ForceRetryError.ts

This file

Path

source/errors/ForceRetryError.ts

31 lines · 1021 bytes · TypeScript

Last changed by

Make `beforeError` hook receive all errors (#829)Sindre Sorhusbefore adoption101c74b

History of this file

Take it

Add `ky.retry()` to force retries from `afterResponse` hooks (#779)Sindre Sorhusbefore adoption68a5228

line 1why, one step back
1import type {ForceRetryOptions} from '../core/constants.js';

Make `beforeError` hook receive all errors (#829)Sindre Sorhusbefore adoption101c74b

line 2why, one step back
2import {KyError} from './KyError.js';

Add `ky.retry()` to force retries from `afterResponse` hooks (#779)Sindre Sorhusbefore adoption68a5228

lines 3–8why, one step back
3import {NonError} from './NonError.js';
45/**6Internal error used to signal a forced retry from afterResponse hooks.7This is thrown when a user returns ky.retry() from an afterResponse hook.8*/

Make `beforeError` hook receive all errors (#829)Sindre Sorhusbefore adoption101c74b

line 9why, one step back
9export class ForceRetryError extends KyError {

Add `ky.retry()` to force retries from `afterResponse` hooks (#779)Sindre Sorhusbefore adoption68a5228

lines 10–31why, one step back
10 override name = 'ForceRetryError' as const;
11 customDelay: number | undefined;12 code: string | undefined;13 customRequest: Request | undefined;1415 constructor(options?: ForceRetryOptions) {16 // Runtime protection: wrap non-Error causes in NonError17 // TypeScript type is Error for guidance, but JS users can pass anything18 const cause = options?.cause19 ? (options.cause instanceof Error ? options.cause : new NonError(options.cause))20 : undefined;2122 super(23 options?.code ? `Forced retry: ${options.code}` : 'Forced retry',24 cause ? {cause} : undefined,25 );2627 this.customDelay = options?.delay;28 this.code = options?.code;29 this.customRequest = options?.request;30 }31}