mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:51:24 +00:00
refactor: consolidate fetchWithTimeout into shared utility
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user