Skip to content

Instantly share code, notes, and snippets.

@arn4v
Created February 17, 2021 15:58
Show Gist options
  • Save arn4v/97e77bbb29dc156b14aa9b1a168dad87 to your computer and use it in GitHub Desktop.
Save arn4v/97e77bbb29dc156b14aa9b1a168dad87 to your computer and use it in GitHub Desktop.
Simple requestretry
/**
* @param {RequestInfo} opts
* @param {number} maxRetries
* @param {number} retryDelay
*/
const fetchRetry = async (opts, maxRetries, retryDelay) => {
let error
for (let i = 0; i < maxRetries; i++) {
try {
if (i > 0) {
await timeout(retryDelay)
return await fetch(opts)
}
} catch (err) {
error = err
}
}
throw error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment