mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user