MCPcopy Index your code
hub / github.com/nodejs/nodejs.org / fetchWithRetry

Function fetchWithRetry

apps/site/next.fetch.mjs:21–38  ·  view source on GitHub ↗
(
  url,
  { maxRetry = 3, delay = 100, ...options } = {}
)

Source from the content-addressed store, hash-verified

19 * @returns {Promise<Response>}
20 */
21export const fetchWithRetry = async (
22 url,
23 { maxRetry = 3, delay = 100, ...options } = {}
24) => {
25 const retries = Math.max(1, Number(maxRetry) || 1);
26 const backoff = Math.max(0, Number(delay) || 0);
27
28 const attemptFetch = attempt =>
29 fetch(url, { ...options, signal: AbortSignal.timeout(30000) }).catch(e => {
30 if (attempt === retries || !isTimeoutError(e)) {
31 throw e;
32 }
33
34 return sleep(backoff * attempt).then(() => attemptFetch(attempt + 1));
35 });
36
37 return attemptFetch(1);
38};

Callers 4

getCalendarEventsFunction · 0.90
fetchOpenCollectiveDataFunction · 0.90
graphqlFunction · 0.90

Calls 1

attemptFetchFunction · 0.85

Tested by

no test coverage detected