Harden DB-reading pages with graceful fallback (no 500 without DB)

/news and six admin pages issued raw prisma reads with no try/catch, so
a DB outage rendered a 500 instead of an empty state. Wrap each read
(try/catch or .catch(() => fallback), preserving select() row types and
notFound() on the user-detail page). Matches the fail-soft pattern used
across the rest of the app.

Verified: tsc 0, next build 0, all public pages 200 against a dead DB.
This commit is contained in:
Simo committed 2026-06-28 16:14:40 +02:00
1 parent 3e8fb794d9
commit d5efbba9f6
7 files changed
+60 -29

No files matched your search

+12 -5
View File
@@ -3,11 +3,18 @@ import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
export default async function AdminDashboard() {
const [users, online, articles] = await Promise.all([
prisma.user.count(),
prisma.user.count({ where: { online: "1" } }),
prisma.websiteArticles.count(),
]);
let users = 0;
let online = 0;
let articles = 0;
try {
[users, online, articles] = await Promise.all([
prisma.user.count(),
prisma.user.count({ where: { online: "1" } }),
prisma.websiteArticles.count(),
]);
} catch {
// DB unavailable — show zeroed stats instead of a 500.
}
const stats = [
{ label: "Users", value: users },