mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-30 11:19:12 +01:00
* fix: fetch timeout for external requests to small * fix: format issue * fix: move clear timeout for fetch to finally
17 lines
538 B
TypeScript
17 lines
538 B
TypeScript
/**
|
|
* Same as fetch, but with a timeout of 10 seconds.
|
|
* https://stackoverflow.com/questions/46946380/fetch-api-request-timeout
|
|
* @param param0 fetch arguments
|
|
* @returns fetch response
|
|
*/
|
|
export const fetchWithTimeout = (...[url, requestInit]: Parameters<typeof fetch>) => {
|
|
const controller = new AbortController();
|
|
|
|
// 10 seconds timeout:
|
|
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
|
|
return fetch(url, { signal: controller.signal, ...requestInit }).finally(() => {
|
|
clearTimeout(timeoutId);
|
|
});
|
|
};
|