Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/site/next-data/generators/majorNodeReleases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import nodevu from '@nodevu/core';

import { fetchWithRetry } from '#site/util/fetch';
import { fetchWithRetry } from '#site/next.fetch.mjs';

/**
* Filters Node.js release data to return only major releases with documented support.
Expand Down
2 changes: 1 addition & 1 deletion apps/site/next-data/generators/supportersData.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs';
import { fetchWithRetry } from '#site/util/fetch';
import { fetchWithRetry } from '#site/next.fetch.mjs';

/**
* Fetches supporters data from Open Collective API, filters active backers,
Expand Down
2 changes: 1 addition & 1 deletion apps/site/next-data/generators/vulnerabilities.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VULNERABILITIES_URL } from '#site/next.constants.mjs';
import { fetchWithRetry } from '#site/util/fetch';
import { fetchWithRetry } from '#site/next.fetch.mjs';

const RANGE_REGEX = /([<>]=?)\s*(\d+)(?:\.(\d+))?/;
const V0_REGEX = /^0\.\d+(\.x)?$/;
Expand Down
2 changes: 1 addition & 1 deletion apps/site/next.calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
BASE_CALENDAR_URL,
SHARED_CALENDAR_KEY,
} from './next.calendar.constants.mjs';
import { fetchWithRetry } from './util/fetch';
import { fetchWithRetry } from './next.fetch.mjs';

/**
*
Expand Down
38 changes: 38 additions & 0 deletions apps/site/next.fetch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @typedef { RequestInit & { maxRetry?: number; delay?: number; }} RetryOptions
*/

const isTimeoutError = e =>
e instanceof Error &&
typeof e.cause === 'object' &&
e.cause !== null &&
'code' in e.cause &&
e.cause.code === 'ETIMEDOUT';

const sleep = ms => new Promise(r => setTimeout(r, ms));

/**
* Does a fetch with retry logic for network errors and timeouts.
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says this retries on “network errors and timeouts”, but the implementation only retries when isTimeoutError(e) is true (ETIMEDOUT via e.cause.code). Either update the documentation to match current behavior or broaden the retry condition to include the intended network-error cases.

Suggested change
* Does a fetch with retry logic for network errors and timeouts.
* Does a fetch with retry logic for timeout errors (as determined by `isTimeoutError`).

Copilot uses AI. Check for mistakes.
*
* @param {string} url
* @param {RetryOptions} [options]
* @returns {Promise<Response>}
*/
export const fetchWithRetry = async (
url,
{ maxRetry = 3, delay = 100, ...options } = {}
) => {
const retries = Math.max(1, Number(maxRetry) || 1);
const backoff = Math.max(0, Number(delay) || 0);

const attemptFetch = attempt =>
fetch(url, options).catch(e => {
if (attempt === retries || !isTimeoutError(e)) {
throw e;
}

return sleep(backoff * attempt).then(() => attemptFetch(attempt + 1));
});

return attemptFetch(1);
};
33 changes: 0 additions & 33 deletions apps/site/util/fetch.ts

This file was deleted.

Loading