Skip to content

Commit

Permalink
fix(with-nestjs): try catch fetch for web app
Browse files Browse the repository at this point in the history
### Description

- Wrap the Links `fetch` request into a try-catch

Co-Authored-By: Anthony Shew <35677084+anthonyshew@users.noreply.github.com>
  • Loading branch information
Neosoulink and anthonyshew committed Jul 12, 2024
1 parent ac3688f commit cca8dc4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/with-nestjs/apps/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ const Gradient = ({
};

const LinksSection = async () => {
const links: Link[] = await (
await fetch('http://localhost:3000/links')
).json();
const fetchLinks = async (): Promise<Link[]> => {
try {
return await (await fetch('http://localhost:3000/links')).json();
} catch (_) {
return [];
}
};

const links = await fetchLinks();

return (
<div className={styles.grid}>
Expand Down

0 comments on commit cca8dc4

Please sign in to comment.