UNPKG

@aws-amplify/core

Version:
36 lines (35 loc) 1.64 kB
import { HttpRequest, HttpResponse, MiddlewareContext, MiddlewareHandler } from '../../types'; import { RetryDeciderOutput } from './types'; /** * Configuration of the retry middleware */ export interface RetryOptions<TResponse extends HttpResponse = HttpResponse> { /** * Function to decide if the request should be retried. * * @param response Optional response of the request. * @param error Optional error thrown from previous attempts. * @param middlewareContext Optional context object to store data between retries. * @returns True if the request should be retried. */ retryDecider(response?: TResponse, error?: unknown, middlewareContext?: MiddlewareContext): Promise<RetryDeciderOutput>; /** * Function to compute the delay in milliseconds before the next retry based * on the number of attempts. * @param attempt Current number of attempts, including the first attempt. * @returns Delay in milliseconds. */ computeDelay(attempt: number): number; /** * Maximum number of retry attempts, starting from 1. Defaults to 3. */ maxAttempts?: number; /** * Optional AbortSignal to abort the retry attempts. */ abortSignal?: AbortSignal; } /** * Middleware that executes the retry logic. */ export declare const retryMiddlewareFactory: <TInput extends HttpRequest = HttpRequest, TOutput extends HttpResponse = HttpResponse>({ maxAttempts, retryDecider, computeDelay, abortSignal, }: RetryOptions<TOutput>) => (next: MiddlewareHandler<TInput, TOutput>, context: MiddlewareContext) => (request: TInput) => Promise<TOutput>;