Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capriza/http-utils

Package Overview
Dependencies
Maintainers
3
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capriza/http-utils - npm Package Compare versions

Comparing version 0.2.5-beta.6 to 0.2.5-beta.7

67

lib/httpUtils.js

@@ -41,2 +41,10 @@ var axios = require('axios');

async patch(url, opts, context) {
return this._callRequest("patch", url, opts, context);
}
async head(url, opts, context) {
return this._callRequest("head", url, opts, context);
}
async downloadUrlAttachment(uri, context) {

@@ -52,16 +60,19 @@ var res = await this.get(uri, {responseType : 'arraybuffer'}, context);

var doRequest = async ()=>{
let options = Object.assign(opts,{
url,
method
});
let options = Object.assign(opts, { url, method });
return this.http.request(options);
};
try {
return await this.http.request(options);
} catch (ex) {
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;
var onError = async (err) => {
if(!retriesCount || !(retriesCount > 0)) {
return reject(this._handleError(err, method, `${opts.baseURL || this.baseURL || ""}${url}`, requestLog));
} else {
let retryReason;
if (err.code && networkErrors.includes(err.code)) retryReason = `network error: ${err.code}`;
else if (err.response && this.retryStatusCodes.includes(err.response.status)) retryReason = `server error: ${err.response.status}`;
if (!retryReason) {
return reject(this._handleError(err, method, `${opts.baseURL || this.baseURL || ""}${url}`, requestLog));
}
requestLog.error(`[HttpUtils] Got ${retryReason} on ${opts.baseURL || this.baseURL || ""}${url} Retrying...`);
await this._delay();

@@ -72,18 +83,2 @@ return this._callRequest(method, url, opts, { priority: true, debug, logger, responseType, retriesCount: retriesCount - 1 });

var onError = (err)=>{
if (err.response) {
requestLog.error(`[HttpUtils] HTTP ${method} response error: ${err.response.status} ${err.response.statusText} on ${opts.baseURL || this.baseURL || ""}${url}`);
reject(err.response);
} else if (err.status) {
requestLog.error(`[HttpUtils] HTTP ${method} response error: ${err.status} ${err.statusText} on ${opts.baseURL || this.baseURL || ""}${url}`);
reject(err);
} else if (err.code){
requestLog.error(`[HttpUtils] HTTP ${method} error: ${err.code} on ${opts.baseURL || this.baseURL || ""}${url}`);
reject(err);
} else {
requestLog.error(`[HttpUtils] HTTP ${method} error: ${err} on ${opts.baseURL || this.baseURL || ""}${url}`);
reject(err);
}
};
if (!["get", "post", "put", "patch", "head"].includes(method)){

@@ -116,2 +111,16 @@ reject(`HTTP request method not defined. ${method}`);

}
_handleError(err, method, url, logger) {
if (err.response) {
logger.error(`[HttpUtils] HTTP ${method} response error: ${err.response.status} ${err.response.statusText} on ${url}`);
return err.response;
} else if (err.status) {
logger.error(`[HttpUtils] HTTP ${method} response error: ${err.status} ${err.statusText} on ${url}`);
} else if (err.code){
logger.error(`[HttpUtils] HTTP ${method} error: ${err.code} on ${url}`);
} else {
logger.error(`[HttpUtils] HTTP ${method} error: ${err} on ${url}`);
}
return err;
}
};
{
"name": "@capriza/http-utils",
"version": "0.2.5-beta.6",
"version": "0.2.5-beta.7",
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication",

@@ -13,2 +13,10 @@ "main": "index.js",

},
"keywords": [
"http",
"https",
"xhr",
"ajax",
"promise",
"node"
],
"author": "Capriza",

@@ -15,0 +23,0 @@ "license": "ISC",

@@ -1,1 +0,1 @@

VERSION=0.2.5-beta.6
VERSION=0.2.5-beta.7
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc