refactor: Services nach Datenquelle getrennt – webservice/, database/ und utils/ Struktur eingeführt (v1.1.117)
This commit is contained in:
18
services/utils/fetchWithTimeout.js
Normal file
18
services/utils/fetchWithTimeout.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// services/api/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;
|
||||
Reference in New Issue
Block a user