Giter Club home page Giter Club logo

node-request-replay's Introduction

request-replay Build Status

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

DO NOT use this module if you are piping request instances. If you are listening to data events to buffer, beware that you must reset everything when a replay occurs. This is why pipping is not supported.

Installation

$ npm install request-replay

Usage

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', 'ESOCKETTIMEDOUT']
replay(request('http://google.com/doodle.png', function (err, response, body) {
    // Do things
}), {
    retries: 10,
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + '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 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 true.

License

Released under the MIT License.

node-request-replay's People

Contributors

satazor avatar ericsaboia avatar

Watchers

Marcello Azambuja avatar Rafael Martins avatar Rafael Floriano da Silva avatar Alex Martins avatar Guilherme Cirne avatar Evandro Flores avatar Igor Macaubas avatar  avatar Andreia avatar Danilo Moura avatar James Cloos avatar Vivien avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.