request-replay

Replays a request when a network error occurs

request-replay

Replays a request when a network error occurs using the retry module.

$ npm install request-replay

var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
 
// Note that the options argument is optional 
// Accepts the same options the retry module does and an additional 
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET'] 
replay(request('http://google.com/doodle.png'), {}})
.on('error', function (err) {
    // Do something with err 
})
.pipe(fs.createWriteStream('doodle.png'))
.on('replay', function (replay) {
    console.log('replay nr:', replay);
})
.on('error', function (err) {
    // Do something with err 
})
.on('close', function (err) {
    // Saved to doogle.png! 
})

Note that the default retry options are modified to be more appropriate for requests:

  • retries: The maximum amount of times to retry the operation. Default is 5.
  • factor: The exponential factor to use. Default is 2.
  • minTimeout: The amount of time before starting the first retry. Default is 2000.
  • maxTimeout: The maximum amount of time between two retries. Default is 35000.
  • randomize: Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.

Released under the MIT License.