Skip to content

Instantly share code, notes, and snippets.

@pinkhominid
Last active February 10, 2021 19:52
Show Gist options
  • Save pinkhominid/ca962b82a12e6adcb6318875576a2fab to your computer and use it in GitHub Desktop.
Save pinkhominid/ca962b82a12e6adcb6318875576a2fab to your computer and use it in GitHub Desktop.
fetch json with retry
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