From c3c61894d2b119ae424bac605d4b3099e0b674e5 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 18 Oct 2026 21:47:21 +0200 Subject: fix: report a duplicate name instead of failing the page Adding a category or project whose name exists, or renaming an item onto an existing name, hit the unique constraint and rendered SvelteKit's 500 page. Translate SQLITE_CONSTRAINT_UNIQUE into a form error on the three forms. --- src/routes/+page.server.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/routes/+page.server.ts') diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index fe9b4e3..008f7f3 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -2,6 +2,7 @@ import { fail } from '@sveltejs/kit'; import { loadOverview } from '$lib/server/services/routines'; import { add as addProject } from '$lib/server/services/projects'; import { parseFormString } from '$lib/server/services/validation'; +import { isUniqueViolation } from '$lib/server/db/errors'; import type { Actions, PageServerLoad } from './$types'; export const load: PageServerLoad = async () => { @@ -14,7 +15,14 @@ export const actions: Actions = { if (!name) { return fail(400, { error: 'Le nom est requis' }); } - await addProject(name); + try { + await addProject(name); + } catch (error) { + if (isUniqueViolation(error)) { + return fail(400, { error: 'Ce projet existe déjà' }); + } + throw error; + } return { success: true }; }, }; -- cgit v1.3