async function fetchWithTimeout(url, { retryCount, timeout }) {
const abortController = new AbortController();
const { signal } = abortController;
const timeId = setTimeout(() => abortController.abort(), timeout);
try {
const response = await fetch(url, { signal });
if (!response.ok) {
throw new Error('Error fetch')
}
return response.json();
} catch(e) {
if (retryCount) {
return retryFetch(url, { retryCount: retryCount-1, timeout })
} else {
throw err;
}
} finally {
clearTimeout(timeId);
}
}
Code will run automatically after changes.
Code runs in an isolated environment.
Code runs in an isolated environment.