Created
February 17, 2021 15:58
-
-
Save arn4v/97e77bbb29dc156b14aa9b1a168dad87 to your computer and use it in GitHub Desktop.
Simple requestretry
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
/** | |
* @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