Merge pull request #27 from rede5/codex/fix-loading-issue-with-users-j268w2

Add timeout handling for API requests
This commit is contained in:
Tiago Yamamoto 2025-12-22 19:52:33 -03:00 committed by GitHub
commit 4b51feeacd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,14 +52,23 @@ async function apiRequest<T>(
const url = `${baseUrl}${cleanEndpoint}`;
console.log(`[API Request] ${url}`); // Debug log
const res = await fetch(url, {
...options,
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
...options.headers,
},
});
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 15000);
let res: Response;
try {
res = await fetch(url, {
...options,
signal: controller.signal,
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
...options.headers,
},
});
} finally {
clearTimeout(timeout);
}
if (!res.ok) {
const error = await res.text();