Last active
February 10, 2021 19:52
-
-
Save pinkhominid/ca962b82a12e6adcb6318875576a2fab to your computer and use it in GitHub Desktop.
fetch json with retry
This file contains hidden or 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
function fetchJSON(url, options, retries = 0) { | |
return fetch(url, { cache: 'no-store', ...options }) | |
.then(res => { | |
if (res.ok) return res.json(); | |
if (retries > 0) return fetchJSON(url, options, --retries); | |
throw res; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment