/** * Fetch with timeout utility function to prevent hanging requests * @param {string} url - The URL to fetch * @param {Object} options - Fetch options * @param {number} timeout - Timeout in milliseconds * @returns {Promise} - The fetch response */ export const fetchWithTimeout = async (url, options, timeout = 10000) => { const controller = new AbortController(); const id = setTimeout(() => controller.abort(), timeout); try { const response = await fetch(url, { ...options, signal: controller.signal }); clearTimeout(id); return response; } catch (error) { clearTimeout(id); throw error; } };