Last active
December 25, 2023 13:08
-
-
Save jakubbarczyk/d66692edbf54a26cd73307fbb957aa45 to your computer and use it in GitHub Desktop.
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
const fetchWithRetries = async (url, options, retryCount = 0) => { | |
const { maxRetries = 3, ...remainingOptions } = options; | |
try { | |
return await fetch(url, remainingOptions); | |
} catch (error) { | |
if (retryCount < maxRetries) { | |
return fetchWithRetries(url, options, retryCount + 1); | |
} | |
throw Error('Max retries exceeded', { cause: error }); | |
} | |
}; | |
export fetchWithRetries; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment