Created
April 15, 2022 00:00
-
-
Save osamaishtiaq/aeeb759c9b9746e501dfd5cbf0206182 to your computer and use it in GitHub Desktop.
Request retry mechanism in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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