retryme
A more intuitive node-retry
which behaves more like async.retry
. Utilizes Backo
under the hood for backoff.
Usage
var Retryme = require('retryme');
var operation = new Retryme({
retries: 2,
min: 50,
max: 10000
});
operation.attempt((next) => {
request('https://whatever.com', (err, res, body) => {
if (err || res.statusCode !== 200) {
return next(err || new Error(`Invalid status code ${res.statusCode}));
}
next(null, body);
}, (err, body) => {
if (err) return /* handle me */
console.dir(body);
});
Now if we want to ignore certain types of errors, we pass a function for configuring those cases
var retry = require('retryme');
const op = retry.op(err => err.message.includes('404'));
op.attempt(next => {
request('https://whatever.com', (err, res, body) => {
if (err || res.statusCode !== 200) {
return next(err || new Error(`Invalid status code ${res.statusCode}));
}
next(null, body);
});
}, (err, body) => {
if (err) return /* handle me */
console.dir(body);
});
test
npm test