generated from coulomb/repo-seed
Optimize dashboard overview loading
This commit is contained in:
@@ -89,11 +89,23 @@ export async function waitForVisible(ms) {
|
||||
export async function apiFetch(path, options = {}) {
|
||||
const url = path.startsWith("http") ? path : `${API}${path}`;
|
||||
const timeout = options.timeout ?? FETCH_TIMEOUT;
|
||||
const {timeout: _timeout, ...fetchOptions} = options;
|
||||
const {timeout: _timeout, cache = "no-store", ...fetchOptions} = options;
|
||||
const ctrl = new AbortController();
|
||||
const timer = setTimeout(() => ctrl.abort(), timeout);
|
||||
let timedOut = false;
|
||||
const timer = setTimeout(() => {
|
||||
timedOut = true;
|
||||
ctrl.abort();
|
||||
}, timeout);
|
||||
try {
|
||||
return await fetch(url, {cache: "no-store", ...fetchOptions, signal: ctrl.signal});
|
||||
return await fetch(url, {cache, ...fetchOptions, signal: ctrl.signal});
|
||||
} catch (error) {
|
||||
if (timedOut || error?.name === "AbortError") {
|
||||
const message = `Request timed out after ${Math.round(timeout / 1000)}s: ${url}`;
|
||||
const timeoutError = new Error(message);
|
||||
timeoutError.name = "TimeoutError";
|
||||
throw timeoutError;
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user