From 4fbfd39736ebf3820bfdefce651adac5f079950c Mon Sep 17 00:00:00 2001 From: AyrisAI Date: Fri, 15 May 2026 20:36:45 +0300 Subject: [PATCH] debug: add try-catch to catch db errors on main page --- app/page.tsx | 81 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 3de2add..febfa2f 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,48 +4,63 @@ import MenuView from "./components/MenuView"; export const dynamic = 'force-dynamic'; export default async function Page() { - const restaurant = await prisma.restaurant.findFirst({ - include: { - categories: { - include: { - items: true, - }, - orderBy: { - createdAt: 'asc', + try { + const restaurant = await prisma.restaurant.findFirst({ + include: { + categories: { + include: { + items: true, + }, + orderBy: { + createdAt: 'asc', + }, }, }, - }, - }); + }); - if (!restaurant) { + if (!restaurant) { + return ( +
+
+

LUNA

+

Henüz menü verisi bulunamadı veya veritabanı bağlantısı kurulamadı.

+

Lütfen admin panelinden bir restoran ve kategori oluşturulduğundan emin olun.

+
+
+ ); + } + + // Map database structure to the structure expected by MenuView + const data = { + restaurant_name: restaurant.name, + footer_note: restaurant.footerNote || "", + categories: restaurant.categories.map(cat => ({ + id: cat.id, + title: cat.title, + externalId: cat.externalId, + items: (cat.items || []).map(item => ({ + name: item.name, + ingredients: item.ingredients, + tasteProfile: item.tasteProfile, + grapeVariety: item.grapeVariety, + price: item.price, + })), + })), + }; + + return ; + } catch (error: any) { + console.error("Database error:", error); return (

LUNA

-

Henüz menü verisi bulunamadı veya veritabanı bağlantısı kurulamadı.

-

Lütfen admin panelinden bir restoran ve kategori oluşturulduğundan emin olun.

+

Veritabanı bağlantısı sırasında bir hata oluştu.

+
+            {error.message || "Bilinmeyen hata"}
+          
); } - - // Map database structure to the structure expected by MenuView - const data = { - restaurant_name: restaurant.name, - footer_note: restaurant.footerNote || "", - categories: restaurant.categories.map(cat => ({ - id: cat.id, - title: cat.title, - externalId: cat.externalId, - items: cat.items.map(item => ({ - name: item.name, - ingredients: item.ingredients, - tasteProfile: item.tasteProfile, - grapeVariety: item.grapeVariety, - price: item.price, - })), - })), - }; - - return ; }