retryable-document-client
Version:
Retryable DynamoDB DocumentClient
27 lines (26 loc) • 807 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var defaults_1 = require("./defaults");
;
;
;
;
var factory = function (calculateTimeout, options) {
var maxAttempts = (options && options.maxAttempts) || defaults_1.default.maxAttempts;
var exceptions = options && options.exceptions;
var handleErr = options && options.handleErr;
return function (err, attempt, cback) {
if (err && (!exceptions || exceptions.includes(err.code))
&& (attempt <= maxAttempts)) {
var timeout = calculateTimeout(attempt);
setTimeout(function () { cback(true); }, timeout);
if (handleErr) {
handleErr(err);
}
}
else {
cback();
}
};
};
exports.default = factory;