feat: better error messages
This commit is contained in:
@@ -17,6 +17,11 @@ export default defineEventHandler(async (event) => {
|
||||
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
||||
const body = await readValidatedBody(event, bodySchema.parse);
|
||||
|
||||
const conflicts = await findConflictingFields(body, params.id);
|
||||
if (conflicts.length > 0) {
|
||||
throw createError({ statusCode: 409, message: `A link with this ${joinFields(conflicts)} already exists` });
|
||||
}
|
||||
|
||||
const [link] = await db
|
||||
.update(tables.links)
|
||||
.set(body)
|
||||
|
||||
@@ -11,6 +11,12 @@ const bodySchema = z.object({
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readValidatedBody(event, bodySchema.parse);
|
||||
|
||||
const conflicts = await findConflictingFields(body);
|
||||
if (conflicts.length > 0) {
|
||||
throw createError({ statusCode: 409, message: `A link with this ${joinFields(conflicts)} already exists` });
|
||||
}
|
||||
|
||||
const [link] = await db.insert(tables.links).values(body).returning();
|
||||
return link;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user