Files
clawdbot/src/infra/provider-usage.fetch.shared.ts
2026-01-14 05:40:03 +00:00

15 lines
371 B
TypeScript

export async function fetchJson(
url: string,
init: RequestInit,
timeoutMs: number,
fetchFn: typeof fetch,
): Promise<Response> {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
return await fetchFn(url, { ...init, signal: controller.signal });
} finally {
clearTimeout(timer);
}
}