Skip to content

Instantly share code, notes, and snippets.

@osamaishtiaq
Created April 15, 2022 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osamaishtiaq/aeeb759c9b9746e501dfd5cbf0206182 to your computer and use it in GitHub Desktop.
Save osamaishtiaq/aeeb759c9b9746e501dfd5cbf0206182 to your computer and use it in GitHub Desktop.
Request retry mechanism in JavaScript
export async function requestWithRetry(requestFunc, errFunc, retryCount = 3) {
try {
return await requestFunc();
} catch (err) {
if (retryCount <= 0) {
errFunc(err);
}
console.log('Request failed, retrying...');
retryCount -= 1;
return await requestWithRetry(requestFunc, errFunc, retryCount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment