function retry(maxRetries, fn) { return fn().catch(function(err) { if (maxRetries <= 0) { throw err; } return retry(maxRetries - 1, fn); }); }