Skip to content

Commit ecd9f5c

Browse files
committed
Added the attempts property and assigned it to the error object returned when a network error occurs
1 parent bb0256e commit ecd9f5c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Install with [npm](https://npmjs.org/package/requestretry).
2525

2626
## Usage
2727

28-
Request-retry is a drop-in replacement for [request](https://github.com/mikeal/request) but adds two new options `maxAttempts` and `retryDelay`. It also adds one property to the response, `attempts`. It supports callbacks or promises.
28+
Request-retry is a drop-in replacement for [request](https://github.com/mikeal/request) but adds two new options `maxAttempts` and `retryDelay`. It also adds one property to the response (or the error object, upon a network error), `attempts`. It supports callbacks or promises.
2929

3030
### With callbacks
3131

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Request.prototype._tryUntilFail = function () {
124124
this._req = Request.request(this.options, function (err, response, body) {
125125
if (response) {
126126
response.attempts = this.attempts;
127+
} else if (err) {
128+
err.attempts = this.attempts;
127129
}
128130
if (this.retryStrategy(err, response, body) && this.maxAttempts > 0) {
129131
this._timeout = setTimeout(this._tryUntilFail.bind(this), this.delayStrategy.call(this, err, response, body));

0 commit comments

Comments
 (0)