MCPcopy Index your code
hub / github.com/anus-dev/ANUS / fetchWithTimeout

Function fetchWithTimeout

packages/core/src/utils/fetch.ts:40–58  ·  view source on GitHub ↗
(
  url: string,
  timeout: number,
)

Source from the content-addressed store, hash-verified

38}
39
40export async function fetchWithTimeout(
41 url: string,
42 timeout: number,
43): Promise<Response> {
44 const controller = new AbortController();
45 const timeoutId = setTimeout(() => controller.abort(), timeout);
46
47 try {
48 const response = await fetch(url, { signal: controller.signal });
49 return response;
50 } catch (error) {
51 if (isNodeError(error) && error.code === 'ABORT_ERR') {
52 throw new FetchError(`Request timed out after ${timeout}ms`, 'ETIMEDOUT');
53 }
54 throw new FetchError(getErrorMessage(error));
55 } finally {
56 clearTimeout(timeoutId);
57 }
58}

Callers 1

executeFallbackMethod · 0.85

Calls 2

isNodeErrorFunction · 0.85
getErrorMessageFunction · 0.85

Tested by

no test coverage detected