Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fetchWithRetry(url, options = {}) {
- const {tries = 1} = options;
- function onError(err){
- const triesLeft = tries - 1;
- if (!triesLeft){
- throw err;
- }
- return fetchWithRetry(url, {...options, tries: triesLeft});
- }
- return fetch(url, options).catch(onError);
- }
Advertisement
Add Comment
Please, Sign In to add comment