Browse Source

Handle unique constraint exception

pull/1583/head
Hironsan 3 years ago
parent
commit
c512ced660
2 changed files with 11 additions and 2 deletions
  1. 7
      backend/api/views/annotation.py
  2. 6
      frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts

7
backend/api/views/annotation.py

@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.shortcuts import get_object_or_404
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
@ -34,7 +35,11 @@ class AnnotationList(generics.ListCreateAPIView):
if self.project.single_class_classification:
self.get_queryset().delete()
request.data['example'] = self.kwargs['doc_id']
return super().create(request, args, kwargs)
try:
response = super().create(request, args, kwargs)
except ValidationError as err:
response = Response({'detail': err.messages}, status=status.HTTP_400_BAD_REQUEST)
return response
def perform_create(self, serializer):
serializer.save(example_id=self.kwargs['doc_id'], user=self.request.user)

6
frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts

@ -20,7 +20,11 @@ export class SequenceLabelingApplicationService extends AnnotationApplicationSer
public async create(projectId: string, docId: number, labelId: number, startOffset: number, endOffset: number): Promise<void> {
const item = new SequenceLabelingLabel(0, labelId, 0, startOffset, endOffset)
await this.repository.create(projectId, docId, item)
try {
await this.repository.create(projectId, docId, item)
} catch(e) {
console.log(e.response.data.detail)
}
}
public async changeLabel(projectId: string, docId: number, annotationId: number, labelId: number): Promise<void> {

Loading…
Cancel
Save