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:
1 parent
3e8fb794d9
commit
d5efbba9f6
7 files changed
+60
-29
No files matched your search
@@ -5,11 +5,16 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminBans() {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const bans = await prisma.ban.findMany({
|
||||
where: { banExpire: { gt: now } },
|
||||
orderBy: { timestamp: "desc" },
|
||||
take: 100,
|
||||
});
|
||||
let bans: Awaited<ReturnType<typeof prisma.ban.findMany>> = [];
|
||||
try {
|
||||
bans = await prisma.ban.findMany({
|
||||
where: { banExpire: { gt: now } },
|
||||
orderBy: { timestamp: "desc" },
|
||||
take: 100,
|
||||
});
|
||||
} catch {
|
||||
bans = [];
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
|
||||
Reference in new issue
Block a user