fix: validation error handling (resolves #3)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { aktis, ratings } from '$lib/server/db/schema';
|
import { aktis, ratings } from '$lib/server/db/schema';
|
||||||
import { error, redirect, type Actions } from '@sveltejs/kit';
|
import { error, fail, redirect, type Actions } from '@sveltejs/kit';
|
||||||
import { and, eq } from 'drizzle-orm';
|
import { and, eq } from 'drizzle-orm';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { ensureAuth } from '$lib/auth';
|
import { ensureAuth } from '$lib/auth';
|
||||||
@@ -54,7 +54,7 @@ export const actions = {
|
|||||||
)
|
)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
if (!changeRequest) return error(400);
|
if (!changeRequest) return fail(400, { message: 'Invalid data' });
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(aktis)
|
.update(aktis)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { ensureAuth } from '$lib/auth';
|
import { ensureAuth } from '$lib/auth';
|
||||||
import { error, redirect, type Actions } from '@sveltejs/kit';
|
import { error, fail, redirect, type Actions } from '@sveltejs/kit';
|
||||||
import { extractFormData } from '$lib/extractFormData';
|
import { extractFormData } from '$lib/extractFormData';
|
||||||
import { aktis, ratings } from '$lib/server/db/schema';
|
import { aktis, ratings } from '$lib/server/db/schema';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
@@ -54,7 +54,7 @@ export const actions = {
|
|||||||
)
|
)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
if (!rating) return error(400);
|
if (!rating) return fail(400, { message: 'Invalid data' });
|
||||||
|
|
||||||
await db.insert(ratings).values({
|
await db.insert(ratings).values({
|
||||||
...rating,
|
...rating,
|
||||||
|
|||||||
Reference in New Issue
Block a user