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

@capriza/http-utils

Package Overview
Dependencies
Maintainers
4
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.0 to 0.2.1

27

lib/httpUtils.js
var axios = require('axios');
var BaseUtils = require("./baseUtils");
var Queue = require("./rateLimitQueue");
const responseTypes = ["data", "status", "statusText", "headers", "config", "request"];

@@ -34,10 +35,2 @@ module.exports = class HttpUtils extends BaseUtils {

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) {

@@ -48,3 +41,3 @@ var res = await this.get(uri, {responseType : 'arraybuffer'}, context);

async _callRequest(method, url, opts = {}, { priority, debug, logger } = {}){
async _callRequest(method, url, opts = {}, { priority, debug, logger, responseType = 'data' } = {}){
const requestLog = logger || this.logger;

@@ -64,5 +57,8 @@ return new Promise((resolve, reject)=>{

reject(err.response);
} else {
} else if (err.code){
requestLog.error(`[HttpUtils] HTTP ${method} error: ${err.code} on ${this.baseURL}${url}`);
reject(err);
} else {
requestLog.error(`[HttpUtils] HTTP ${method} error: ${err} on ${this.baseURL}${url}`);
reject(err);
}

@@ -80,5 +76,14 @@ };

this.requestQueue.add(doRequest, {priority}).then((response)=>resolve(response.data)).catch(onError);
this.requestQueue.add(doRequest, {priority}).then((response)=>{
if(responseTypes.includes(responseType)) {
return resolve(response[responseType]);
} else if(responseType == "full") {
return resolve(response);
} else {
return reject(`[HttpUtils] responseType = ${responseType} does't valid.`);
}
}).catch(onError);
});
}
};
{
"name": "@capriza/http-utils",
"version": "0.2.0",
"version": "0.2.1",
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication",

@@ -5,0 +5,0 @@ "main": "index.js",

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