Skip to content

Commit

Permalink
pass error to retries option
Browse files Browse the repository at this point in the history
Closes #119
  • Loading branch information
floatdrop committed Dec 20, 2015
1 parent a34c96f commit 59aa1d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -56,7 +56,7 @@ function requestAsEventEmitter(opts) {
});

req.once('error', function (err) {
var backoff = opts.retries(++retryCount);
var backoff = opts.retries(++retryCount, err);
if (backoff) {
setTimeout(get, backoff, opts);
return;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -123,7 +123,7 @@ Default: `5`

Number of request retries when network errors happens. Delays between retries counts with function `Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0).

Option accepts `function` with `retry` argument that must return delay in milliseconds (`0` return value cancels retry).
Option accepts `function` with `retry` and `error` arguments. Function must return delay in milliseconds (`0` return value cancels retry).

##### callback(error, data, response)

Expand Down
11 changes: 11 additions & 0 deletions test/retry.js
Expand Up @@ -58,6 +58,17 @@ test('falsy value prevent retries', async t => {
}
});

test('falsy value prevent retries', async t => {
try {
await got(`${s.url}/long`, {timeout: 100, retries: (iter, err) => {
t.ok(err);
return false;
}});
} catch (err) {
t.ok(err);
}
});

test.after('cleanup', async t => {
await s.close();
});

0 comments on commit 59aa1d3

Please sign in to comment.