MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / fetchWithTimeout

Function fetchWithTimeout

netlify/functions/_shared/middleware.js:364–382  ·  view source on GitHub ↗

* 创建带超时的 fetch 包装器 * @param {string} url - 请求 URL * @param {Object} options - fetch 选项 * @param {number} timeout - 超时时间(毫秒) * @returns {Promise }

(url, options = {}, timeout = 30000)

Source from the content-addressed store, hash-verified

362 * @returns {Promise<Response>}
363 */
364async function fetchWithTimeout(url, options = {}, timeout = 30000) {
365 const controller = new AbortController();
366 const timeoutId = setTimeout(() => controller.abort(), timeout);
367
368 try {
369 const response = await fetch(url, {
370 ...options,
371 signal: controller.signal
372 });
373 clearTimeout(timeoutId);
374 return response;
375 } catch (error) {
376 clearTimeout(timeoutId);
377 if (error.name === 'AbortError') {
378 throw new Error(`Request timeout after ${timeout}ms`);
379 }
380 throw error;
381 }
382}
383
384module.exports = {
385 authenticate,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected