Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 58efcaf

Browse files
author
Manuel Proß
committed
feat(web): add error handling
1 parent ad4f384 commit 58efcaf

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

web/src/app/layout.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,35 @@ async function getPageProps() {
2828
const query = qs.stringify(params, { addQueryPrefix: true });
2929

3030
try {
31-
const response = await fetch(`${process.env.CMS_API}/menus/1${query}`, {
32-
// headers: {
33-
// authorization: `Bearer ${process.env.CMS_TOKEN}`,
34-
// },
35-
});
36-
37-
return (await response.json()).data.attributes.items.data;
31+
const response = await fetch(`${process.env.CMS_API}/menus/1${query}`);
32+
if (!response.ok) {
33+
throw new Error(`Failed to fetch data: ${response.status} ${response.statusText}`);
34+
}
35+
const data = await response.json();
36+
return data.data.attributes.items.data;
3837
} catch (error) {
38+
console.error("Error fetching page props:", error);
3939
return [];
4040
}
4141
}
4242

4343
export default async function RootLayout({ children }: { children: React.ReactNode }) {
44-
const pageProps = await getPageProps();
45-
const session = await getServerSession();
44+
let pageProps;
45+
let session;
46+
47+
try {
48+
pageProps = await getPageProps();
49+
} catch (error) {
50+
console.error("Error getting page props:", error);
51+
pageProps = [];
52+
}
53+
54+
try {
55+
session = await getServerSession();
56+
} catch (error) {
57+
console.error("Error getting server session:", error);
58+
session = null;
59+
}
4660

4761
return (
4862
<SessionProvider session={session}>

0 commit comments

Comments
 (0)