# request-replay

> Replays a request when a network error occurs

Latest version **1.0.4** (published 2016-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install request-replay
pnpm add request-replay
yarn add request-replay
bun add request-replay
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2016-08-20 |
| First published | 2013-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | IndigoUnited |
| Maintainers | satazor |
| Keywords | retry, replay, request, mikeal, network |

## Links

- npm: https://www.npmjs.com/package/request-replay
- Repository: https://github.com/IndigoUnited/node-request-replay
- Homepage: https://github.com/IndigoUnited/node-request-replay#readme
- Issues: http://github.com/IndigoUnited/node-request-replay/issues
- npm.io page: https://npm.io/package/request-replay

## Dependencies (1)

- [retry](https://npm.io/package/retry.md) ^0.10.0

## Recent versions

- 1.0.4 (latest) — 2016-08-20
- 1.0.3 — 2016-01-26
- 1.0.2 — 2016-01-04
- 1.0.1 — 2016-01-03
- 1.0.0 — 2016-01-03
- 0.3.0 — 2013-11-27
- 0.2.0 — 2013-08-03
- 0.1.10 — 2013-08-02
- 0.1.8 — 2013-08-02
- 0.1.7 — 2013-08-01
- 0.1.6 — 2013-08-01
- 0.1.5 — 2013-07-31
- 0.1.4 — 2013-07-20
- 0.1.3 — 2013-07-20
- 0.1.1 — 2013-07-20

## README

# request-replay

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]

[npm-url]:https://npmjs.org/package/request-replay
[downloads-image]:http://img.shields.io/npm/dm/request-replay.svg
[npm-image]:http://img.shields.io/npm/v/request-replay.svg
[travis-url]:https://travis-ci.org/IndigoUnited/node-request-replay
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-request-replay/master.svg
[david-dm-url]:https://david-dm.org/IndigoUnited/node-request-replay
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-request-replay.svg
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-request-replay#info=devDependencies
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-request-replay.svg

Replays a [request](https://github.com/mikeal/request) when a network error occurs using the [retry](https://github.com/felixge/node-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

```js
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 it
replay(request('http://google.com/doodle.png', { timeout: 10000 }, function (err, response, body) {
    // Do things
}), {
    retries: 10,
    factor: 3
})
.on('socket', function (socket) {
    // In some operating systems the socket timeout is 0 so you must explicitly set it
    // and close the socket once reached
    socket.setTimeout(10000, socket.end.bind(socket));
})
.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](http://www.opensource.org/licenses/mit-license.php).

---
_Source: https://npm.io/package/request-replay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
