mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-01-26 16:39:47 +00:00
Add better error messages if name exists when saving a job
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user