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);
|
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 });
|
return NextResponse.json({ error: 'Failed to save training data' }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,12 @@ export default function TrainingForm() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error saving training:', error);
|
if (error.response?.status === 409) {
|
||||||
setStatus('error');
|
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(() =>
|
.finally(() =>
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user