From f1a1f51a782dfc99c498b1b62922decc9141a2f4 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sat, 6 Jan 2024 17:12:48 +0100 Subject: [PATCH] Handle non 2xx codes as an error --- src/server.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server.tsx b/src/server.tsx index 0e5f32e..4f258bd 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -78,6 +78,9 @@ async function fetchWithTimeout(url: string, timeout: number = TIMEOUT): Promise async function fetchAndHandle(url: string): Promise { try { const response = await fetchWithTimeout(url, TIMEOUT); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } console.debug(`Successfully fetched data from ${url}`); const contentType = response.headers.get("content-type"); if (contentType?.includes("application/json")) {