refactor: consolidate fetchWithTimeout into shared utility

This commit is contained in:
quotentiroler
2026-02-09 20:34:56 -08:00
parent 757522fb48
commit a26670a2fb
7 changed files with 56 additions and 90 deletions

View File

@@ -1,6 +1,7 @@
import type { GuardedFetchResult } from "../../infra/net/fetch-guard.js";
import type { LookupFn, SsrFPolicy } from "../../infra/net/ssrf.js";
import { fetchWithSsrFGuard } from "../../infra/net/fetch-guard.js";
export { fetchWithTimeout } from "../../utils/fetch-timeout.js";
const MAX_ERROR_CHARS = 300;
@@ -9,21 +10,6 @@ export function normalizeBaseUrl(baseUrl: string | undefined, fallback: string):
return raw.replace(/\/+$/, "");
}
export async function fetchWithTimeout(
url: string,
init: RequestInit,
timeoutMs: number,
fetchFn: typeof fetch,
): Promise<Response> {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), Math.max(1, timeoutMs));
try {
return await fetchFn(url, { ...init, signal: controller.signal });
} finally {
clearTimeout(timer);
}
}
export async function fetchWithTimeoutGuarded(
url: string,
init: RequestInit,