eh-api-client
Advanced tools
Comparing version 0.27.0 to 0.28.0
@@ -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(); | ||
}); | ||
}); | ||
}); | ||
}); |
74342
14
1729