axios-retry
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -30,3 +30,6 @@ import isRetryAllowed from 'is-retry-allowed'; | ||
*/ | ||
export default function axiosRetry(axios, { retries = 3 } = {}) { | ||
export default function axiosRetry(axios, { | ||
retries = 3, | ||
retryCondition = error => !error.response | ||
} = {}) { | ||
axios.interceptors.response.use(null, error => { | ||
@@ -42,3 +45,3 @@ const config = error.config; | ||
const shouldRetry = !error.response | ||
const shouldRetry = retryCondition(error) | ||
&& error.code !== 'ECONNABORTED' | ||
@@ -45,0 +48,0 @@ && config.retryCount < retries |
@@ -46,2 +46,6 @@ 'use strict'; | ||
var retries = _ref$retries === undefined ? 3 : _ref$retries; | ||
var _ref$retryCondition = _ref.retryCondition; | ||
var retryCondition = _ref$retryCondition === undefined ? function (error) { | ||
return !error.response; | ||
} : _ref$retryCondition; | ||
@@ -58,3 +62,3 @@ axios.interceptors.response.use(null, function (error) { | ||
var shouldRetry = !error.response && error.code !== 'ECONNABORTED' && config.retryCount < retries && (0, _isRetryAllowed2.default)(error); | ||
var shouldRetry = retryCondition(error) && error.code !== 'ECONNABORTED' && config.retryCount < retries && (0, _isRetryAllowed2.default)(error); | ||
@@ -61,0 +65,0 @@ if (shouldRetry) { |
{ | ||
"name": "axios-retry", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"author": "Rubén Norte <ruben.norte@softonic.com>", | ||
@@ -5,0 +5,0 @@ "description": "Axios plugin that intercepts failed requests and retries them whenever posible.", |
@@ -37,2 +37,9 @@ # axios-retry | ||
## Options | ||
| Name | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| retries | `Number` | 3 | The number of times to retry before failing | | ||
| retryCondition | `Function` | `error => !error.response` | A callback to further control if a request should be retried. By default, it retries if the result did not have a response. | | ||
## Testing | ||
@@ -39,0 +46,0 @@ |
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
10971
7
130
60