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

@altangent/http-client

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@altangent/http-client - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

2

package.json
{
"name": "@altangent/http-client",
"version": "2.2.0",
"version": "2.2.1",
"description": "Simple promise based http/https client for Node",

@@ -5,0 +5,0 @@ "main": "src",

@@ -8,3 +8,6 @@ const http = require('http');

function request(opts, { idleTimeoutMs = 10000, connectionTimeoutMs = 10000, parseJson = true } = {}) {
function request(
opts,
{ idleTimeoutMs = 10000, connectionTimeoutMs = 10000, parseJson = true } = {}
) {
return new Promise((resolve, reject) => {

@@ -26,14 +29,21 @@ function callback(res) {

let body = Buffer.concat(buffers);
if(!parseJson) return resolve(body);
let json = JSON.parse(body);
if (json.error) {
let error = new Error('HTTPS failed with error payload');
error.statusCode = res.statusCode;
error.request = opts;
error.body = json;
return reject(error);
if (!parseJson) return resolve(body);
try {
let json = JSON.parse(body);
if (json.error) {
let error = new Error('HTTPS failed with error payload');
error.statusCode = res.statusCode;
error.request = opts;
error.body = json;
return reject(error);
}
else {
return resolve(json);
}
}
else {
return resolve(json);
catch (ex) {
let err = new Error('Invalid JSON response');
err.subError = ex;
err.body = body.toString();
return reject(err);
}

@@ -40,0 +50,0 @@ }

@@ -56,6 +56,20 @@ const nock = require('nock');

});
describe('when error in json response', () => {
describe('when invalid json response', () => {
before(async () => {
nock('https://test')
.get('/somepath')
.reply(200, '{"bad":');
await run();
});
it('should reject with error', () => {
expect(result.message).to.equal('Invalid JSON response');
});
it('should include sub-body', () => {
expect(result.body).to.equal('{"bad":');
});
});
describe('when error object in json response', () => {
before(async () => {
nock('https://test')
.get('/somepath')
.reply(200, { error: 'things went poorly' });

@@ -62,0 +76,0 @@ await run();

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