Replays a request when a network error occurs
DO NOT use this module if you are piping
If you are listening to
data events to buffer, beware that you must reset everything when a
This is why
pipping is not supported.
$ 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 with error codes that cause the replay to happen// Check out the code to see which is the default value for itreplayrequest'' timeout: 10000// Do thingsretries: 10factor: 3on'socket'// In some operating systems the socket timeout is 0 so you must explicitly set it// and close the socket once reachedsocketsetTimeout10000 socketendbindsocket;on'replay'// "replay" is an object that contains some useful informationconsole.log'request failed: ' + replay.errorcode + ' ' + replay.errormessage;console.log'replay nr: #' + replaynumber;console.log'will retry in: ' + replaydelay + 'ms';
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
factor: The exponential factor to use. Default is
minTimeout: The amount of time before starting the first retry. Default is
maxTimeout: The maximum amount of time between two retries. Default is
randomize: Randomizes the timeouts by multiplying with a factor between
2. Default is
Released under the MIT License.