chore: remove unused request timeout fetch wrapper (#5331)

Verified dead-code removal: merged result passes typecheck:core + 194 affected unit tests + ESLint clean. Integrated into release/v3.8.41. Thanks @JxnLexn for the cleanup!
This commit is contained in:
Jan Leon
2026-06-29 15:07:07 +02:00
committed by GitHub
parent 8e3a110fb6
commit 105f0c84da
2 changed files with 7 additions and 40 deletions

View File

@@ -7,46 +7,6 @@
* @module shared/utils/requestTimeout
*/
interface TimeoutOptions {
timeoutMs?: number;
label?: string;
signal?: AbortSignal;
}
export async function fetchWithTimeout(url: string, options: RequestInit & TimeoutOptions = {}) {
const { timeoutMs = 30000, label = "Request", signal: externalSignal, ...fetchOptions } = options;
const controller = new AbortController();
// Merge with external signal if provided
if (externalSignal) {
externalSignal.addEventListener("abort", () => controller.abort(externalSignal.reason));
}
const timeoutId = setTimeout(() => {
controller.abort(new Error(`${label} timed out after ${timeoutMs}ms`));
}, timeoutMs);
try {
const response = await fetch(url, {
...fetchOptions,
signal: controller.signal,
});
return response;
} catch (error: any) {
if (error.name === "AbortError" || controller.signal.aborted) {
const timeoutError: any = new Error(`${label} timed out after ${timeoutMs}ms`);
timeoutError.name = "TimeoutError";
timeoutError.originalUrl = url;
timeoutError.timeoutMs = timeoutMs;
throw timeoutError;
}
throw error;
} finally {
clearTimeout(timeoutId);
}
}
/**
* Execute any async function with a timeout.
*

View File

@@ -136,8 +136,15 @@ test("CircuitBreaker: calls onStateChange callback", async () => {
// ─── Request Timeout Tests ───────────────────────────
import * as requestTimeout from "../../src/shared/utils/requestTimeout.ts";
import { withTimeout, getProviderTimeout } from "../../src/shared/utils/requestTimeout.ts";
test("requestTimeout: public surface excludes removed fetch wrapper", () => {
assert.equal(Object.hasOwn(requestTimeout, "fetchWithTimeout"), false);
assert.equal(typeof requestTimeout.withTimeout, "function");
assert.equal(typeof requestTimeout.getProviderTimeout, "function");
});
test("requestTimeout: withTimeout resolves before timeout", async () => {
const result = await withTimeout(async () => "fast", 1000, "test");
assert.equal(result, "fast");