You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

  1. from rest_framework import status
  2. from rest_framework.exceptions import (APIException, PermissionDenied,
  3. ValidationError)
  4. class FileParseException(APIException):
  5. status_code = status.HTTP_400_BAD_REQUEST
  6. default_detail = 'Invalid file format, line {}: {}'
  7. default_code = 'invalid'
  8. def __init__(self, line_num, line, code=None):
  9. detail = self.default_detail.format(line_num, line)
  10. super().__init__(detail, code)
  11. class AutoLabelingException(APIException):
  12. status_code = status.HTTP_400_BAD_REQUEST
  13. default_detail = 'Auto labeling not allowed for the document with labels.'
  14. class AutoLabeliingPermissionDenied(PermissionDenied):
  15. default_detail = 'You do not have permission to perform auto labeling.' \
  16. 'Please ask the project administrators to add you.'
  17. class URLConnectionError(ValidationError):
  18. default_detail = 'Failed to establish a connection. Please check the URL or network.'
  19. class AWSTokenError(ValidationError):
  20. default_detail = 'The security token included in the request is invalid.'
  21. class SampleDataException(ValidationError):
  22. default_detail = 'The response is empty. Maybe the sample data is not appropriate.' \
  23. 'Please specify another sample data which returns at least one label.'
  24. class TemplateMappingError(ValidationError):
  25. default_detail = 'The response cannot be mapped. You might need to change the template.'
  26. class LabelValidationError(APIException):
  27. status_code = status.HTTP_400_BAD_REQUEST
  28. default_detail = 'You cannot create a label with same name or shortcut key.'
  29. class AnnotationRelationValidationError(APIException):
  30. status_code = status.HTTP_400_BAD_REQUEST
  31. default_detail = 'You cannot create an annotation relation between the same annotation.'
  32. class RelationTypesValidationError(APIException):
  33. status_code = status.HTTP_400_BAD_REQUEST
  34. default_detail = 'You cannot create a relation type with same name or color.'
  35. class RoleConstraintException(APIException):
  36. status_code = status.HTTP_400_BAD_REQUEST
  37. default_detail = 'The project needs at least one administrator.'
  38. class RoleAlreadyAssignedException(APIException):
  39. status_code = status.HTTP_400_BAD_REQUEST
  40. default_detail = 'This user is already assigned to a role in this project.'