cc_site_maker / utils /fetch-utils.js
postApocalebtic
Local Server Fix
1f0573c
Raw History Blame
661 Bytes
/**
* 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<Response>} - 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;
}
};