eh-api-client
Advanced tools
Comparing version 0.30.1 to 0.30.2
@@ -207,31 +207,38 @@ var | ||
var args = [].slice.call(arguments); | ||
// if request has failed and body is stream, do not retry request | ||
if(err && retryOptions && !bodyStream) { | ||
var strategySupported = retryOptions.retryStrategy(err, params); | ||
var maxAttemptsReached = numTry >= retryOptions.maxAttempts; | ||
if(!strategySupported) { | ||
debuglog("Retry strategy doesn't support error", err); | ||
if(err) { | ||
err.retryInfo = { | ||
try: numTry | ||
}; | ||
// if request has failed and body is stream, do not retry request | ||
if(retryOptions && !bodyStream) { | ||
var strategySupported = retryOptions.retryStrategy(err, params); | ||
var maxAttemptsReached = numTry >= retryOptions.maxAttempts; | ||
if(!strategySupported) { | ||
debuglog("Retry strategy doesn't support error", err); | ||
} | ||
if(maxAttemptsReached) { | ||
debuglog("Too much attempts with", err); | ||
} | ||
if(maxAttemptsReached || !strategySupported) { | ||
err.retryInfo = { | ||
try: numTry, | ||
strategySupported: strategySupported | ||
}; | ||
var debugParams = _.clone(params); | ||
delete debugParams.agent; | ||
err.requestParams = debugParams; | ||
return cb(err); | ||
} | ||
numTry++; | ||
// retry | ||
return setTimeout(function() { | ||
self._tryRequest(params, numTry, cb); | ||
}, retryOptions.retryDelay); | ||
} | ||
if(maxAttemptsReached) { | ||
debuglog("Too much attempts with", err); | ||
} | ||
if(maxAttemptsReached || !strategySupported) { | ||
err.retryInfo = { | ||
try: numTry, | ||
strategySupported: strategySupported | ||
}; | ||
var debugParams = _.clone(params); | ||
delete debugParams.agent; | ||
err.requestParams = debugParams; | ||
return cb(err); | ||
} | ||
numTry++; | ||
// retry | ||
return setTimeout(function() { | ||
self._tryRequest(params, numTry, cb); | ||
}, retryOptions.retryDelay); | ||
} | ||
res.retryInfo = { | ||
try: numTry | ||
}; | ||
else if(res) { | ||
res.retryInfo = { | ||
try: numTry | ||
}; | ||
} | ||
cb.apply(null, args); | ||
@@ -238,0 +245,0 @@ }); |
{ | ||
"name": "eh-api-client", | ||
"version": "0.30.1", | ||
"version": "0.30.2", | ||
"description": "Node.js rest client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -80,11 +80,3 @@ var | ||
s.on("request", function(req, res) { | ||
var gotData = ""; | ||
req.on("data", function(chunk) { | ||
gotData += chunk.toString(); | ||
}); | ||
req.on("end", function() { | ||
res.end(JSON.stringify({ | ||
requested: gotData | ||
})); | ||
}) | ||
req.socket.destroy(); | ||
}); | ||
@@ -98,3 +90,3 @@ done(); | ||
it("should stream request", function(done) { | ||
it("shouldn't retry if body is a stream", function(done) { | ||
var stream = new TestReadStream({}, ["1", "2", "3"]); | ||
@@ -105,4 +97,4 @@ client.setAgentOptions({ | ||
client.put("/", stream, function(err, data, res) { | ||
should.not.exists(err); | ||
data.requested.should.equal("123"); | ||
should.exists(err); | ||
err.retryInfo.try.should.equal(1); | ||
done(); | ||
@@ -109,0 +101,0 @@ }); |
77336
1831