retry-axios
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -44,2 +44,6 @@ import { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
noResponseRetries?: number; | ||
/** | ||
* Backoff Type; 'linear', 'static' or 'exponential'. | ||
*/ | ||
backoffType?: 'linear' | 'static' | 'exponential'; | ||
} | ||
@@ -46,0 +50,0 @@ export declare type RaxConfig = { |
@@ -67,2 +67,3 @@ "use strict"; | ||
config.instance = config.instance || axios_1.default; | ||
config.backoffType = config.backoffType || 'exponential'; | ||
config.httpMethodsToRetry = normalizeArray(config.httpMethodsToRetry) || [ | ||
@@ -106,3 +107,12 @@ 'GET', | ||
// Formula: (2^c - 1 / 2) * 1000 | ||
const delay = ((Math.pow(2, config.currentRetryAttempt) - 1) / 2) * 1000; | ||
let delay; | ||
if (config.backoffType === 'linear') { | ||
delay = config.currentRetryAttempt * 1000; | ||
} | ||
else if (config.backoffType === 'static') { | ||
delay = config.retryDelay; | ||
} | ||
else { | ||
delay = ((Math.pow(2, config.currentRetryAttempt) - 1) / 2) * 1000; | ||
} | ||
// We're going to retry! Incremenent the counter. | ||
@@ -109,0 +119,0 @@ err.config.raxConfig.currentRetryAttempt += 1; |
{ | ||
"name": "retry-axios", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Retry HTTP requests with Axios.", | ||
@@ -5,0 +5,0 @@ "main": "./build/src/index.js", |
# retry-axios | ||
> Use Axios interceptors to automatically retry failed requests. Super flexible. Built in exponential backoff. | ||
> Use Axios interceptors to automatically retry failed requests. Super flexible. Built in exponential backoff. | ||
@@ -79,2 +79,6 @@ [![NPM Version][npm-image]][npm-url] | ||
// You can set the backoff type. | ||
// options are 'exponential' (default), 'static' or 'linear' | ||
backoffType: 'exponential', | ||
// You can detect when a retry is happening, and figure out how many | ||
@@ -81,0 +85,0 @@ // retry attempts have been made |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30600
251
151