Request wrapper with retries, focused on streaming
npm install request-retry-stream    
npm install request-retry-stream
Request wrapper with retries, supports streaming. Takes the same options as the
request module.
NOTE: only GET http requests are supported when streaming.
There is support for POST, PUT, DELETE and PATCH retrying using callbacks but not streaming
(be careful with retrying POST it's not idempotent)
Non-2XX http statusCodes are returned as errors with
the information needed for debugging.
If you want to pass non-2XX error-codes through when streaming use the optionpassThrough: true
``javascript
var rrs = require('request-retry-stream');
rrs.get({url: 'http://google.com', timeout: 5000}, function(err, resp){
// handle err and resp. Any response that does not have http status code 2XX is an error here
});
`
The error returned in case of non 2XX, has all the options passed to rrs,
as well as a statusCode, message, stack, attemptsDone and the body returned
for the request.
`js`
{
message: 'Error in request statusCode: 400',
stack: '...[STACKTRACE]...',
statusCode: 400,
url: 'http://example.com',
attemptsDone: 1,
method: 'POST'
body: '...[BODY RETURNED FROM REQUEST]...'
timeout: 5000
}
`javascript
var rrs = require('request-retry-stream');
var pump = require('pump');
function(req, res, next){
pump(rrs.get('http://google.com', {timeout: 5000}), res, next);
}
`
`javascript
var rrs = require('request-retry-stream');
var pump = require('pump');
function(req, res, next){
var stream = rrs.get({
url: 'http://google.com',
attempts: 3, //default
delay: 500, //default
timeout: 2000,
logFunction: console.warn // optional, if you want to be notified about retry
});
pump(stream, res, next);
}
``