@capriza/http-utils
Advanced tools
Comparing version 0.2.15 to 0.2.16
var axios = require('axios'); | ||
var BaseUtils = require("./baseUtils"); | ||
var Queue = require("./rateLimitQueue"); | ||
@@ -11,5 +10,4 @@ const CancelToken = axios.CancelToken; | ||
module.exports = class HttpUtils extends BaseUtils { | ||
module.exports = class HttpUtils { | ||
constructor(options = {}){ | ||
super(options); | ||
this.baseURL = options.baseURL || options.baseUrl; | ||
@@ -24,2 +22,4 @@ this.retryInterval = (!isNaN(options.retryInterval) && options.retryInterval) || 5000; | ||
this.requestQueue = new Queue(options.limit, options.interval, options.maxConcurrent); | ||
this.loggingLevel = options.loggingLevel || "debug"; | ||
this.logger = this._getValidLogger(options.logger); | ||
this.http = axios.create(Object.assign(options.requestConfig || {}, { | ||
@@ -63,3 +63,3 @@ baseURL: this.baseURL, | ||
retriesCount = retriesCount === undefined ? this.maxRetries : retriesCount; | ||
const requestLog = logger || this.logger; | ||
const requestLog = this._getValidLogger(logger); | ||
return new Promise((resolve, reject) => { | ||
@@ -89,3 +89,3 @@ try { | ||
var timeout = setTimeout(() => { | ||
requestLog.info("request time exceeded"); | ||
requestLog[this.loggingLevel]("request time exceeded"); | ||
try { | ||
@@ -132,5 +132,4 @@ source.cancel('request was canceled due to time out'); | ||
} | ||
requestLog[this.loggingLevel](`[HttpUtils] PRIORITY[${priority ? priority : 0}] HTTP ${method} request: ${cleanURL}`); | ||
requestLog.debug(`[HttpUtils] PRIORITY[${priority ? priority : 0}] HTTP ${method} request: ${cleanURL}`); | ||
this.requestQueue.add(doRequest, {priority}).then((response) => { | ||
@@ -167,2 +166,10 @@ if(responseTypes.includes(responseType)) { | ||
} | ||
_getValidLogger(logger) { | ||
if(!logger || typeof logger[this.loggingLevel] !== "function" || typeof logger.error !== "function") { | ||
return this.logger || console; | ||
} | ||
return logger; | ||
} | ||
}; |
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.2.15", | ||
"version": "0.2.16", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,1 @@ | ||
VERSION=0.2.14 | ||
VERSION=0.2.15 | ||
VERSION=0.2.16 |
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
40647
30
560
12