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 fileTake it
1234567891011121314151617181920212223242526272829303132import type {ForceRetryOptions} from '../core/constants.js';import {KyError} from './KyError.js';import {NonError} from './NonError.js';
/**Internal error used to signal a forced retry from afterResponse hooks.This is thrown when a user returns ky.retry() from an afterResponse hook.*/export class ForceRetryError extends KyError { override name = 'ForceRetryError' as const; customDelay: number | undefined; code: string | undefined; customRequest: Request | undefined;
constructor(options?: ForceRetryOptions) { // Runtime protection: wrap non-Error causes in NonError // TypeScript type is Error for guidance, but JS users can pass anything const cause = options?.cause ? (options.cause instanceof Error ? options.cause : new NonError(options.cause)) : undefined;
super( options?.code ? `Forced retry: ${options.code}` : 'Forced retry', cause ? {cause} : undefined, );
this.customDelay = options?.delay; this.code = options?.code; this.customRequest = options?.request; }}