@capriza/http-utils
Advanced tools
Comparing version 0.2.14 to 0.2.15
@@ -18,4 +18,4 @@ var axios = require('axios'); | ||
this.retryStatusCodes = (Array.isArray(options.retryStatusCodes) && options.retryStatusCodes) || retryStatusCodes; | ||
this.networkErrors = (Array.isArray(options.networkErrors) && options.networkErrors) || networkErrors; | ||
this.retryOnNetworkErrors = options.retryOnNetworkErrors || false; | ||
options.retryNetworkErrors = options.retryNetworkErrors || options.networkErrors; | ||
this.retryNetworkErrors = (Array.isArray(options.retryNetworkErrors) && options.retryNetworkErrors) || (options.retryOnNetworkErrors !== false ? networkErrors : []); | ||
const requestTimeout = parseInt(options.requestTimeout); | ||
@@ -113,3 +113,3 @@ this.requestTimeout = requestTimeout === 0 ? 0 : (requestTimeout || 5 * 60 * 1000); | ||
let retryReason; | ||
if (err.code && this.networkErrors.includes(err.code)) retryReason = `network error: ${err.code}`; | ||
if (err.code && this.retryNetworkErrors.includes(err.code)) retryReason = `network error: ${err.code}`; | ||
else if (err.response && this.retryStatusCodes.includes(err.response.status)) retryReason = `server error: ${err.response.status}`; | ||
@@ -116,0 +116,0 @@ |
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.2.14", | ||
"version": "0.2.15", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
VERSION=0.2.14 | ||
VERSION=0.2.15 |
@@ -12,3 +12,3 @@ # @capriza/http-utils | ||
- [retryInterval](#retryInterval) | ||
- [retryOnNetworkErrors](#retryOnNetworkErrors) | ||
- [retryNetworkErrors](#retryNetworkErrors) | ||
- [retryStatusCodes](#retryStatusCodes) | ||
@@ -52,3 +52,3 @@ - [limit](#limit) | ||
### maxRetries | ||
Maximum retries permitted in case of server or network errors, depending on settings of [retryStatusCodes](#retryStatusCodes) and [retryOnNetworkErrors](#retryOnNetworkErrors), respectively. | ||
Maximum retries permitted in case of server or network errors, depending on settings of [retryStatusCodes](#retryStatusCodes) and [retryNetworkErrors](#retryNetworkErrors), respectively. | ||
<br /> | ||
@@ -60,6 +60,6 @@ default: `0` | ||
### retryOnNetworkErrors | ||
Triggers retry of request when `ECONNABORTED` or `ECONNRESET` response is received. | ||
### retryNetworkErrors | ||
If one of these values is received as the error code of the response, a retry of the request will be triggered. | ||
<br /> | ||
default: `false` | ||
default: `["ECONNABORTED", "ECONNRESET"]` | ||
@@ -114,3 +114,2 @@ ### retryStatusCodes | ||
interval: 10 * 1000, | ||
retryOnNetworkErrors: true, | ||
maxRetries: 3, | ||
@@ -145,3 +144,2 @@ retryStatusCodes: [502, 503] | ||
headers, | ||
retryOnNetworkErrors: true, | ||
retryStatusCodes: [502, 503] | ||
@@ -148,0 +146,0 @@ maxRetries: 3 |
@@ -51,3 +51,33 @@ const HttpUtils = require('../lib/httpUtils'); | ||
it("#4 - Should not retry by status code 404", async () => { | ||
it("#4 - Check NOT retry (backward) by network error", async () => { | ||
server.setResponses([ | ||
{ status: 504, delay: 2100 }, | ||
{ status: 200 } | ||
]); | ||
try { | ||
httpUtils = new HttpUtils({ baseURL: server.url, maxRetries: 1, retryOnNetworkErrors: false, requestTimeout: 2000 }); | ||
await httpUtils.get(`/` ); | ||
} catch (e) { | ||
if(e.code !== "ECONNABORTED") throw "Should not retry!" | ||
} | ||
}); | ||
it("#5 - Check NOT retry (backward) by network error", async () => { | ||
server.setResponses([ | ||
{ status: 504, delay: 2100 }, | ||
{ status: 200 } | ||
]); | ||
try { | ||
httpUtils = new HttpUtils({ baseURL: server.url, maxRetries: 1, retryNetworkErrors: [], requestTimeout: 2000 }); | ||
await httpUtils.get(`/` ); | ||
} catch (e) { | ||
if(e.code !== "ECONNABORTED") throw "Should not retry!" | ||
} | ||
}); | ||
it("#6 - Should not retry by status code 404", async () => { | ||
server.setResponses([ { status: 404 } ]); | ||
@@ -64,3 +94,3 @@ httpUtils = new HttpUtils({ baseURL: server.url, maxRetries: 1 }); | ||
it("#5 - Should retry by status code 404 if override status codes", async () => { | ||
it("#7 - Should retry by status code 404 if override status codes", async () => { | ||
server.setResponses([ | ||
@@ -67,0 +97,0 @@ { status: 404 }, |
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
40519
559
149