Skip to content

Commit d0b1750

Browse files
committed
update readme
1 parent fa48977 commit d0b1750

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Request-retry [![Deps](https://david-dm.org/FGRibreau/node-request-retry.png)](https://david-dm.org/FGRibreau/node-request-retry)
1+
# Request-retry [![Deps](https://david-dm.org/FGRibreau/node-request-retry.png)](https://david-dm.org/FGRibreau/node-request-retry) [![Build Status](https://drone.io/github.com/FGRibreau/node-request-retry/status.png)](https://drone.io/github.com/FGRibreau/node-request-retry/latest)
22

33
[![npm](https://nodei.co/npm/requestretry.png)](https://npmjs.org/package/requestretry)
44

@@ -18,6 +18,7 @@ request({
1818
// The above parameters are specific to Request-retry:
1919
maxAttempts: 5, // (default) try 5 times
2020
retryDelay: 5000 // (default) wait for 5s before trying again
21+
retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
2122
}, function(err, response, body){
2223
// this callback will only be called when the request succeeded or after maxAttempts or on error
2324
});
@@ -29,14 +30,42 @@ Install with [npm](https://npmjs.org/package/requestretry).
2930

3031
npm install --save requestretry
3132

33+
## Define your own retry strategy
34+
35+
```
36+
/**
37+
* @param {Null | Object} err
38+
* @param {Object} response
39+
* @return {Boolean} true if the request should be retried
40+
*/
41+
function myRetryStrategy(err, response){
42+
// retry the request if we had an error or if the response was a 'Bad Gateway'
43+
return err || response.statusCode === 502;
44+
}
45+
46+
request({
47+
url: 'https://api.domain.com/v1/a/b'
48+
json:true,
49+
maxAttempts: 5,
50+
retryDelay: 5000
51+
retryStrategy: myRetryStrategy
52+
}, function(err, response, body){
53+
// this callback will only be called when the request succeeded or after maxAttempts or on error
54+
});
55+
```
56+
3257
## Todos
3358

3459
- Tests
3560
- Use an EventEmitter to notify retries
36-
- Allow the end-user to specify its own conditions to trigger a retry
3761

3862
## Changelog
3963

64+
v1.2.0
65+
66+
- support for user-defined retry strategies
67+
- added `request.RetryStrategies.HTTPError`, `request.RetryStrategies.NetworkError` and `request.RetryStrategies.HTTPOrNetworkError`
68+
4069
v1.1.0
4170

4271
- support for 'end', 'on', 'emit', 'once', 'setMaxListeners', 'start', 'removeListener', 'pipe' request methods by @juliendangers

0 commit comments

Comments
 (0)