@capriza/http-utils
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -6,2 +6,3 @@ var axios = require('axios'); | ||
const retryStatusCodes = [502, 503, 504]; | ||
const networkErrors = ["ECONNABORTED", "ECONNRESET"]; | ||
@@ -14,2 +15,3 @@ module.exports = class HttpUtils extends BaseUtils { | ||
this.retryStatusCodes = (Array.isArray(options.retryStatusCodes) && options.retryStatusCodes) || retryStatusCodes; | ||
this.retryOnNetworkErrors = options.retryOnNetworkErrors || false; | ||
@@ -59,5 +61,7 @@ this.requestQueue = new Queue(options.limit, options.interval, options.maxConcurrent); | ||
} catch (ex) { | ||
if(!this.maxRetries || !ex || !ex.response || !this.retryStatusCodes.includes(ex.response.status)) throw ex; | ||
requestLog.error(`[HttpUtils] Got status ${ex.response.status} on ${opts.baseURL || this.baseURL || ""}${url}${retriesCount === 0 ? `. Reached max retries: ${this.maxRetries}` : " Retrying..."}`); | ||
let shouldRetry = false; | ||
if(this.retryOnNetworkErrors && ex.code && networkErrors.includes(ex.code)) shouldRetry = "network error"; | ||
if(this.maxRetries && ex && ex.response && this.retryStatusCodes.includes(ex.response.status)) shouldRetry = "server error"; | ||
if(!shouldRetry) throw ex; | ||
requestLog.error(`[HttpUtils] Got ${shouldRetry} with ${shouldRetry === "network error" ? "code " + ex.code : "status " + ex.response.status} on ${opts.baseURL || this.baseURL || ""}${url}${retriesCount === 0 ? `. Reached max retries: ${this.maxRetries}` : ` Retrying ${shouldRetry}...`}`); | ||
if(!(retriesCount > 0)) throw ex; | ||
@@ -64,0 +68,0 @@ await this._delay(); |
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
28729
346