feat: complete admin error handling improvements - add error display to articles pages

- Add error display to articles pages (overview, edit, new)
- Improve createArticle action to handle database errors gracefully
- Redirect with error query params for user feedback on failure
- Completes error handling improvements across admin pages
- Enhances error reporting for better user experience
This commit is contained in:
remco committed 2026-07-01 21:32:59 +02:00
1 parent 0323c3fcaa
commit 4a06b30263
4 files changed
+51 -16

No files matched your search

+18 -13
View File
@@ -24,19 +24,24 @@ export async function createArticle(formData: FormData): Promise<void> {
const image = String(formData.get("image") ?? "").trim();
if (!title) return;
const now = new Date();
await prisma.websiteArticles.create({
data: {
slug: await uniqueSlug(title),
title: title.slice(0, 255),
shortStory: shortStory.slice(0, 255),
fullStory,
image: image.slice(0, 255),
userId: staff.id,
createdAt: now,
updatedAt: now,
},
});
try {
const now = new Date();
await prisma.websiteArticles.create({
data: {
slug: await uniqueSlug(title),
title: title.slice(0, 255),
shortStory: shortStory.slice(0, 255),
fullStory,
image: image.slice(0, 255),
userId: staff.id,
createdAt: now,
updatedAt: now,
},
});
} catch (error) {
// Database error — re-render unchanged with error.
redirect("/admin/articles/new?error=Database error while creating article. Please try again.");
}
redirect("/admin/articles");
}