Skip to content

Instantly share code, notes, and snippets.

@vilmid
Created June 8, 2021 14:12
Show Gist options
  • Select an option

  • Save vilmid/577858bdb62d7b5c22ba1e65c7bc72da to your computer and use it in GitHub Desktop.

Select an option

Save vilmid/577858bdb62d7b5c22ba1e65c7bc72da to your computer and use it in GitHub Desktop.
/**
* @param {string} url
* @param {Object} options
* @param {Number} attempt
* @returns {Promise<Response>}
*/
const fetchWithRetry = async (url, options, attempt) => {
try {
return await fetch(url, options)
} catch (err) {
if (attempt === 1) throw err
return await fetchWithRetry(url, options, attempt - 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment