@nuskin/axios-util
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "@nuskin/axios-util", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "An Axios utility ...", | ||
@@ -22,18 +22,18 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"axios": "0.27.2", | ||
"axios-mock-adapter": "1.19.0", | ||
"eslint": "7.19.0", | ||
"eslint-config-google": "0.14.0", | ||
"eslint-config-prettier": "7.2.0", | ||
"eslint-plugin-prettier": "3.3.1", | ||
"jest": "26.6.3", | ||
"axios": "1.5.0", | ||
"axios-mock-adapter": "1.22.0", | ||
"eslint": "8.50.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-json": "3.1.0", | ||
"eslint-plugin-prettier": "5.0.0", | ||
"jest": "29.7.0", | ||
"jest-sonar-reporter": "2.0.0", | ||
"prettier": "2.2.1" | ||
"prettier": "3.0.3" | ||
}, | ||
"dependencies": { | ||
"axios-retry": "3.5.0", | ||
"deepmerge": "4.2.2" | ||
"axios-retry": "3.8.0", | ||
"deepmerge": "4.3.1" | ||
}, | ||
"peerDependencies": { | ||
"axios": "^0.27.2" | ||
"axios": "^1.5.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "files": [ |
@@ -37,11 +37,28 @@ # @nuskin/axios-util | ||
```js | ||
const { axios, getRetryAxiosInstance } = require('@nuskin/axios-util') | ||
const { getRetryAxiosInstance } = require('@nuskin/axios-util') | ||
// Custom retry delay | ||
let retryDelay = process.env.AXIOS_RETRY_DELAY || 5000 | ||
const myAxiosWithRetry = getRetryAxiosInstance({ | ||
retries: 3, | ||
shouldResetTimeout: true, | ||
retryDelay: (retryCount) => { | ||
return retryCount * 1000; | ||
} | ||
retries: 3, | ||
shouldResetTimeout: true, | ||
retryDelay: (retryCount) => { | ||
return retryCount * retryDelay | ||
}, | ||
retryCondition: (error) => { | ||
// if retry condition is not specified, by default idempotent requests are retried | ||
return error.response?.status >= 500 || error.code === 'ECONNABORTED' | ||
}, | ||
onRetry: (retryCount, error, requestConfig) => { | ||
log.info( | ||
{ | ||
retryCount, | ||
message: error.message, | ||
statusCode: error.response?.status, | ||
statusText: error.response?.statusText, | ||
responseData: error.response?.data | ||
}, | ||
requestConfig.metric | ||
) | ||
return true | ||
} | ||
}) | ||
@@ -48,0 +65,0 @@ ``` |
@@ -14,3 +14,3 @@ 'use strict' | ||
/** | ||
* | ||
* | ||
* @param {Object} options `axios-retry` options to pass in. | ||
@@ -20,3 +20,3 @@ * @returns {AxiosInstance} | ||
const getRetryAxiosInstance = (options = {}) => { | ||
const retryConfig = merge({ retryDelay: axiosRetry.exponentialDelay }, options) | ||
const retryConfig = merge({ retryDelay: axiosRetry.exponentialDelay }, options) | ||
const axiosRetryInstance = axios.create() | ||
@@ -30,2 +30,2 @@ axiosRetry(axiosRetryInstance, retryConfig) | ||
getRetryAxiosInstance | ||
} | ||
} |
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
3802
24
77
+ Addedaxios@1.7.9(transitive)
+ Addedaxios-retry@3.8.0(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.27.2(transitive)
- Removedaxios-retry@3.5.0(transitive)
- Removeddeepmerge@4.2.2(transitive)
Updatedaxios-retry@3.8.0
Updateddeepmerge@4.3.1