Add better error messages if name exists when saving a job

This commit is contained in:
Jaret Burkett
2025-04-03 11:25:25 -06:00
parent ac1ee559c5
commit b0d0466efd
2 changed files with 13 additions and 3 deletions

View File

@@ -52,7 +52,13 @@ export async function POST(request: Request) {
});
return NextResponse.json(training);
}
} catch (error) {
} catch (error: any) {
if (error.code === 'P2002') {
// Handle unique constraint violation, 409=Conflict
return NextResponse.json({ error: 'Job name already exists' }, { status: 409 });
}
console.error(error);
// Handle other errors
return NextResponse.json({ error: 'Failed to save training data' }, { status: 500 });
}
}