* Fetch with timeout - prevents hanging on network issues
(
url: string,
options: RequestInit = {},
)
| 20 | * Fetch with timeout - prevents hanging on network issues |
| 21 | */ |
| 22 | async 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 |
| 46 | const repoSchema = z.object({ |
no test coverage detected