Skip to content

Commit

Permalink
Handle non 2xx codes as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Jan 6, 2024
1 parent bef1bc2 commit f1a1f51
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ async function fetchWithTimeout(url: string, timeout: number = TIMEOUT): Promise
async function fetchAndHandle(url: string): Promise<string | object | null> {
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")) {
Expand Down

0 comments on commit f1a1f51

Please sign in to comment.