diff --git a/src/shared/utils/requestTimeout.ts b/src/shared/utils/requestTimeout.ts index 4d493c45d4..ae12ac39af 100644 --- a/src/shared/utils/requestTimeout.ts +++ b/src/shared/utils/requestTimeout.ts @@ -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. * diff --git a/tests/unit/observability-fase04.test.ts b/tests/unit/observability-fase04.test.ts index ad6cf560ef..b5feed55b2 100644 --- a/tests/unit/observability-fase04.test.ts +++ b/tests/unit/observability-fase04.test.ts @@ -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");