Socket
Socket
Sign inDemoInstall

eh-api-client

Package Overview
Dependencies
50
Maintainers
2
Versions
97
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.27.0 to 0.28.0

lib/networkerror.js

4

index.js

@@ -22,4 +22,4 @@ var

}
// only retry if got an ECONNRESET error
return err.code === "ECONNRESET";
// only retry if got an ECONNRESET/ETIMEDOUT error
return err.code === "ECONNRESET" || err.code === "ETIMEDOUT";
}

@@ -26,0 +26,0 @@ };

@@ -5,3 +5,4 @@ var

_ = require("lodash"),
debuglog = require("util").debuglog("eh-api-client");
debuglog = require("util").debuglog("eh-api-client"),
NetworkError = require("./networkerror");

@@ -46,5 +47,5 @@ var methods = [

function buildNetworkError(origErr) {
var error = new Error();
error.name = "NetworkError";
error.message = origErr.code;
var error = new NetworkError(origErr.code);
error.retryInfo = origErr.retryInfo;
error.requestParams = origErr.requestParams;
return error;

@@ -147,2 +148,5 @@ }

}
if(options.timeout) {
reqParams.timeout = options.timeout;
}
// _res will store result of http request, for return in callback

@@ -213,2 +217,5 @@ var _res, _req;

};
var debugParams = _.clone(params);
delete debugParams.agent;
err.requestParams = debugParams;
return cb(err);

@@ -232,3 +239,3 @@ }

params.agent = this._factory.agent;
_.extend(params, this._factory.requestOptions);
_.defaults(params, this._factory.requestOptions);
return Promise.each(this._requestModificators, function(modificator) {

@@ -235,0 +242,0 @@ return modificator(params);

{
"name": "eh-api-client",
"version": "0.27.0",
"version": "0.28.0",
"description": "Node.js rest client",

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

@@ -58,5 +58,2 @@ var

var client = new Factory(url);
client.setRequestOptions({
timeout: 1000
});
// disable keeping alive

@@ -84,9 +81,31 @@ client.setAgentOptions({

it("should return network error when timeout out", function(done) {
client.get("/", function(err) {
client.get({
url: "/",
timeout: 1000
}, function(err) {
err.name.should.equal("NetworkError");
err.message.should.equal("ETIMEDOUT");
err.retryInfo.try.should.be.greaterThan(1);
err.retryInfo.strategySupported.should.equal(true);
done();
});
});
it("shouldn't return network error when set longer timeout", function(done) {
client.get({
url: "/",
timeout: 6000
}, function(err) {
should.not.exists(err);
done();
});
});
it("shouldn't return network error with default timeout", function(done) {
client.get("/", function(err) {
should.not.exists(err);
done();
});
});
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc