1 | import { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
2 | /**
|
3 | * Configuration for the Axios `request` method.
|
4 | */
|
5 | export interface RetryConfig {
|
6 | /**
|
7 | * The number of times to retry the request. Defaults to 3.
|
8 | */
|
9 | retry?: number;
|
10 | /**
|
11 | * The number of retries already attempted.
|
12 | */
|
13 | currentRetryAttempt?: number;
|
14 | /**
|
15 | * The amount of time to initially delay the retry. Defaults to 100.
|
16 | */
|
17 | retryDelay?: number;
|
18 | /**
|
19 | * The instance of the axios object to which the interceptor is attached.
|
20 | */
|
21 | instance?: AxiosInstance;
|
22 | /**
|
23 | * The HTTP Methods that will be automatically retried.
|
24 | * Defaults to ['GET','PUT','HEAD','OPTIONS','DELETE']
|
25 | */
|
26 | httpMethodsToRetry?: string[];
|
27 | /**
|
28 | * The HTTP response status codes that will automatically be retried.
|
29 | * Defaults to: [[100, 199], [429, 429], [500, 599]]
|
30 | */
|
31 | statusCodesToRetry?: number[][];
|
32 | /**
|
33 | * Function to invoke when a retry attempt is made.
|
34 | */
|
35 | onRetryAttempt?: (err: AxiosError) => void;
|
36 | /**
|
37 | * Function to invoke which determines if you should retry
|
38 | */
|
39 | shouldRetry?: (err: AxiosError) => boolean;
|
40 | /**
|
41 | * When there is no response, the number of retries to attempt. Defaults to 2.
|
42 | */
|
43 | noResponseRetries?: number;
|
44 | /**
|
45 | * Backoff Type; 'linear', 'static' or 'exponential'.
|
46 | */
|
47 | backoffType?: 'linear' | 'static' | 'exponential';
|
48 | /**
|
49 | * Whether to check for 'Retry-After' header in response and use value as delay. Defaults to true.
|
50 | */
|
51 | checkRetryAfter?: boolean;
|
52 | /**
|
53 | * Max permitted Retry-After value (in ms) - rejects if greater. Defaults to 5 mins.
|
54 | */
|
55 | maxRetryAfter?: number;
|
56 | /**
|
57 | * Ceiling for calculated delay (in ms) - delay will not exceed this value.
|
58 | */
|
59 | maxRetryDelay?: number;
|
60 | }
|
61 | export declare type RaxConfig = {
|
62 | raxConfig: RetryConfig;
|
63 | } & AxiosRequestConfig;
|
64 | /**
|
65 | * Attach the interceptor to the Axios instance.
|
66 | * @param instance The optional Axios instance on which to attach the
|
67 | * interceptor.
|
68 | * @returns The id of the interceptor attached to the axios instance.
|
69 | */
|
70 | export declare function attach(instance?: AxiosInstance): number;
|
71 | /**
|
72 | * Eject the Axios interceptor that is providing retry capabilities.
|
73 | * @param interceptorId The interceptorId provided in the config.
|
74 | * @param instance The axios instance using this interceptor.
|
75 | */
|
76 | export declare function detach(interceptorId: number, instance?: AxiosInstance): void;
|
77 | /**
|
78 | * Determine based on config if we should retry the request.
|
79 | * @param err The AxiosError passed to the interceptor.
|
80 | */
|
81 | export declare function shouldRetryRequest(err: AxiosError): boolean;
|
82 | /**
|
83 | * Acquire the raxConfig object from an AxiosError if available.
|
84 | * @param err The Axios error with a config object.
|
85 | */
|
86 | export declare function getConfig(err: AxiosError): RetryConfig | undefined;
|
87 | declare module 'axios' {
|
88 | interface AxiosRequestConfig {
|
89 | raxConfig?: RetryConfig;
|
90 | }
|
91 | }
|