debug: add try-catch to catch db errors on main page
This commit is contained in:
81
app/page.tsx
81
app/page.tsx
@@ -4,48 +4,63 @@ import MenuView from "./components/MenuView";
|
|||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const restaurant = await prisma.restaurant.findFirst({
|
try {
|
||||||
include: {
|
const restaurant = await prisma.restaurant.findFirst({
|
||||||
categories: {
|
include: {
|
||||||
include: {
|
categories: {
|
||||||
items: true,
|
include: {
|
||||||
},
|
items: true,
|
||||||
orderBy: {
|
},
|
||||||
createdAt: 'asc',
|
orderBy: {
|
||||||
|
createdAt: 'asc',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!restaurant) {
|
if (!restaurant) {
|
||||||
|
return (
|
||||||
|
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||||||
|
<div>
|
||||||
|
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||||||
|
<p>Henüz menü verisi bulunamadı veya veritabanı bağlantısı kurulamadı.</p>
|
||||||
|
<p style={{ fontSize: '0.8rem', color: '#666' }}>Lütfen admin panelinden bir restoran ve kategori oluşturulduğundan emin olun.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 <MenuView data={data} />;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Database error:", error);
|
||||||
return (
|
return (
|
||||||
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||||||
<div>
|
<div>
|
||||||
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||||||
<p>Henüz menü verisi bulunamadı veya veritabanı bağlantısı kurulamadı.</p>
|
<p>Veritabanı bağlantısı sırasında bir hata oluştu.</p>
|
||||||
<p style={{ fontSize: '0.8rem', color: '#666' }}>Lütfen admin panelinden bir restoran ve kategori oluşturulduğundan emin olun.</p>
|
<pre style={{ fontSize: '0.7rem', color: '#ff4d4d', marginTop: '10px', overflowX: 'auto', maxWidth: '80vw' }}>
|
||||||
|
{error.message || "Bilinmeyen hata"}
|
||||||
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 <MenuView data={data} />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user