Files
nodeMap/services/utils/fetchWithTimeout.js
2025-05-20 13:58:53 +02:00

19 lines
460 B
JavaScript

// services/utils/fetchWithTimeout.js
const fetchWithTimeout = (url, options, timeout = 5000) => {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
return fetch(url, { ...options, signal: controller.signal })
.then((response) => {
clearTimeout(id);
return response;
})
.catch((error) => {
clearTimeout(id);
throw error;
});
};
export default fetchWithTimeout;