retry-request
Advanced tools
Comparing version 2.0.0 to 2.0.1
31
index.js
@@ -38,3 +38,6 @@ 'use strict'; | ||
var MAX_NO_RESPONSE_RETRIES = 2; | ||
var numAttempts = 0; | ||
var numNoResponseAttempts = 0; | ||
@@ -93,10 +96,24 @@ var retryStream; | ||
function retryAfterDelay(numAttempts) { | ||
if (streamMode) { | ||
resetStreams(); | ||
} | ||
setTimeout(makeRequest, getNextRetryDelay(numAttempts)); | ||
} | ||
function onResponse(err, response, body) { | ||
// An error such as DNS resolution. | ||
if (err) { | ||
if (streamMode) { | ||
retryStream.emit('error', err); | ||
retryStream.end(); | ||
numNoResponseAttempts++; | ||
if (numNoResponseAttempts <= MAX_NO_RESPONSE_RETRIES) { | ||
retryAfterDelay(numNoResponseAttempts); | ||
} else { | ||
callback(err, response, body); | ||
if (streamMode) { | ||
retryStream.emit('error', err); | ||
retryStream.end(); | ||
} else { | ||
callback(err, response, body); | ||
} | ||
} | ||
@@ -109,7 +126,3 @@ | ||
if (numAttempts <= opts.retries && opts.shouldRetryFn(response)) { | ||
if (streamMode) { | ||
resetStreams(); | ||
} | ||
setTimeout(makeRequest, getNextRetryDelay(numAttempts)); | ||
retryAfterDelay(numAttempts); | ||
return; | ||
@@ -116,0 +129,0 @@ } |
{ | ||
"name": "retry-request", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Retry a request.", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha --timeout 12000" | ||
"test": "mocha --timeout 0" | ||
}, | ||
@@ -11,0 +11,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7821
116