Skip to content

Commit

Permalink
refactor: Handle error response in getNews function
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaJi committed Aug 7, 2024
1 parent b0cc3d8 commit 22fb949
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export async function getNews(game: string) {
},
});

const data = await res.json() as Promise<News[]>;
if (!res.ok) {
console.error("Error fetching news:", res.statusText);
return [];
}

const data = (await res.json()) as Promise<News[]>;

return data ?? [];
} catch (error) {
Expand Down

0 comments on commit 22fb949

Please sign in to comment.