promise-retry
Advanced tools
Comparing version 0.2.7 to 0.2.8
16
index.js
@@ -7,2 +7,8 @@ 'use strict'; | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
function isRetryError(err) { | ||
return err && err.code === 'EPROMISERETRY' && hasOwn.call(err, 'retried'); | ||
} | ||
function promiseRetry(fn, options) { | ||
@@ -17,8 +23,8 @@ var operation = retry.operation(options); | ||
return fn(function (err) { | ||
if (err && err.code === 'EPROMISERETRY') { | ||
err = err.original; | ||
if (isRetryError(err)) { | ||
err = err.retried; | ||
} | ||
throw errcode('Retrying', 'EPROMISERETRY', { | ||
original: err | ||
retried: err | ||
}); | ||
@@ -29,4 +35,4 @@ }, number); | ||
promise.done(resolve, function (err) { | ||
if (err && err.code === 'EPROMISERETRY') { | ||
err = err.original; | ||
if (isRetryError(err)) { | ||
err = err.retried; | ||
@@ -33,0 +39,0 @@ if (operation.retry(err || new Error())) { |
{ | ||
"name": "promise-retry", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -93,2 +93,21 @@ 'use strict'; | ||
it('should not retry on rejection if nr of retries is 0', function (done) { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
.thenThrow(new Error('foo')) | ||
.catch(retry); | ||
}, { retries : 0 }) | ||
.then(function () { | ||
throw new Error('should not succeed'); | ||
}, function (err) { | ||
expect(err.message).to.be('foo'); | ||
expect(count).to.be(1); | ||
}) | ||
.done(done, done); | ||
}); | ||
it('should reject the promise if the retries were exceeded', function (done) { | ||
@@ -95,0 +114,0 @@ var count = 0; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13776
247
1