From 7873c880fb38dee417df2bfbdfb4cac0e1e9f22b Mon Sep 17 00:00:00 2001 From: Yee Kit Date: Sat, 27 Jan 2024 02:14:24 +0800 Subject: [PATCH] Added timeout for fetch in header --- frontend/app/components/header.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/app/components/header.tsx b/frontend/app/components/header.tsx index 4b33842..81553ec 100644 --- a/frontend/app/components/header.tsx +++ b/frontend/app/components/header.tsx @@ -140,7 +140,9 @@ export default function Header() { const { data: apiStatus, error: apiError } = useSWR(healthcheck_api, async (url) => { try { // Fetch the data - const response = await fetch(url); + const response = await fetch(url, { + signal: AbortSignal.timeout(5000), // Abort the request if it takes longer than 5 seconds + }); if (!response.ok) { throw new Error(response.statusText || 'Unknown Error'); }