diff --git a/ui/src/app/api/jobs/route.ts b/ui/src/app/api/jobs/route.ts index 4d9b954e..c489088d 100644 --- a/ui/src/app/api/jobs/route.ts +++ b/ui/src/app/api/jobs/route.ts @@ -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 }); } } diff --git a/ui/src/app/jobs/new/page.tsx b/ui/src/app/jobs/new/page.tsx index a5e69c24..4819d6dd 100644 --- a/ui/src/app/jobs/new/page.tsx +++ b/ui/src/app/jobs/new/page.tsx @@ -104,8 +104,12 @@ export default function TrainingForm() { } }) .catch(error => { - console.error('Error saving training:', error); - setStatus('error'); + if (error.response?.status === 409) { + alert('Training name already exists. Please choose a different name.'); + } else { + alert('Failed to save job. Please try again.'); + } + console.log('Error saving training:', error); }) .finally(() => setTimeout(() => {