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 });
}
}

View File

@@ -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(() => {