Skip to content

Commit

Permalink
Merge pull request #17 from LN-Zap/respose-code-check
Browse files Browse the repository at this point in the history
Handle non 2xx codes as an error
  • Loading branch information
mrfelton authored Jan 6, 2024
2 parents bef1bc2 + f1a1f51 commit 5894420
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 5894420

Please sign in to comment.