Retries a function until it succeeds or the number of retries is reached.
function to retry
options
const fetchData = retry( async () => { const response = await fetch('https://api.example.com/data'); return response.json(); }, { retries: 3, delay: 1000, backoff: 2, shouldRetry: (error) => error.message.includes('500') });const data = await fetchData(); Copy
const fetchData = retry( async () => { const response = await fetch('https://api.example.com/data'); return response.json(); }, { retries: 3, delay: 1000, backoff: 2, shouldRetry: (error) => error.message.includes('500') });const data = await fetchData();
Retries a function until it succeeds or the number of retries is reached.