From 41336e3af344b895f50a8f2005c6bd6b848508cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Wed, 3 Dec 2025 13:37:59 +0100 Subject: [PATCH] =?UTF-8?q?Curators=20API:=20aussagekr=C3=A4ftige=20Fehler?= =?UTF-8?q?=20bei=20doppelten=20Usernames=20(P2002)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/curators/route.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/api/curators/route.ts b/app/api/curators/route.ts index aff08ec..4450651 100644 --- a/app/api/curators/route.ts +++ b/app/api/curators/route.ts @@ -1,5 +1,5 @@ import { NextRequest, NextResponse } from 'next/server'; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient, Prisma } from '@prisma/client'; import bcrypt from 'bcryptjs'; import { requireAdminAuth } from '@/lib/auth'; @@ -69,6 +69,15 @@ export async function POST(request: NextRequest) { }); } catch (error) { console.error('Error creating curator:', error); + + // Handle unique username constraint violation explicitly + if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === 'P2002') { + return NextResponse.json( + { error: 'A curator with this username already exists.' }, + { status: 409 } + ); + } + return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); } } @@ -153,6 +162,15 @@ export async function PUT(request: NextRequest) { }); } catch (error) { console.error('Error updating curator:', error); + + // Handle unique username constraint violation explicitly for updates + if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === 'P2002') { + return NextResponse.json( + { error: 'A curator with this username already exists.' }, + { status: 409 } + ); + } + return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); } }