From aab5822f48bc5140f49b0e51c590b007187ee401 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Mon, 22 Dec 2025 19:51:54 -0300 Subject: [PATCH] Add timeout to API requests --- frontend/src/lib/api.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 5f73f0e..eb5be3f 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -52,14 +52,23 @@ async function apiRequest( 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();