MCPcopy Create free account
hub / github.com/TanStack/ai / fetchWithTimeout

Function fetchWithTimeout

examples/ts-code-mode-web/src/lib/tools/github-tools.ts:22–43  ·  view source on GitHub ↗

* Fetch with timeout - prevents hanging on network issues

(
  url: string,
  options: RequestInit = {},
)

Source from the content-addressed store, hash-verified

20 * Fetch with timeout - prevents hanging on network issues
21 */
22async function fetchWithTimeout(
23 url: string,
24 options: RequestInit = {},
25): Promise<Response> {
26 const controller = new AbortController()
27 const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT)
28
29 try {
30 const response = await fetch(url, {
31 ...options,
32 signal: controller.signal,
33 })
34 return response
35 } catch (error) {
36 if (error instanceof Error && error.name === 'AbortError') {
37 throw new Error(`Request timed out after ${FETCH_TIMEOUT}ms`)
38 }
39 throw error
40 } finally {
41 clearTimeout(timeoutId)
42 }
43}
44
45// Schema definitions for reuse
46const repoSchema = z.object({

Callers 1

github-tools.tsFile · 0.70

Calls 2

abortMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected