UNPKG

@just-every/ensemble

Version:

LLM provider abstraction layer with unified streaming interface

25 lines 883 B
export async function fetchWithTimeout(url, init = {}, timeoutMs = 20000) { const controller = new AbortController(); const id = setTimeout(() => { const reason = new Error(`Fetch to ${url} timed out after ${timeoutMs}ms`); controller.abort(reason); }, timeoutMs); try { return await fetch(url, { ...init, signal: controller.signal }); } catch (error) { if (error?.name === 'AbortError') { const message = typeof error?.message === 'string' && error.message.trim() !== '' ? error.message : `Fetch to ${url} was aborted`; const timeoutError = new Error(message); timeoutError.name = 'AbortError'; throw timeoutError; } throw error; } finally { clearTimeout(id); } } //# sourceMappingURL=fetch_with_timeout.js.map