2017-12-07 05:01:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2020-07-31 10:18:52 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-07-06 03:14:20 +00:00
|
|
|
from rest_framework.exceptions import APIException
|
2020-07-29 06:57:44 +00:00
|
|
|
from rest_framework import status
|
2017-12-07 05:01:33 +00:00
|
|
|
|
2020-07-06 03:14:20 +00:00
|
|
|
|
|
|
|
class JMSException(APIException):
|
2020-07-29 06:57:44 +00:00
|
|
|
status_code = status.HTTP_400_BAD_REQUEST
|
2020-07-31 10:18:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class JMSObjectDoesNotExist(APIException):
|
|
|
|
status_code = status.HTTP_404_NOT_FOUND
|
|
|
|
default_code = 'object_does_not_exist'
|
|
|
|
default_detail = _('%s object does not exist.')
|
|
|
|
|
|
|
|
def __init__(self, detail=None, code=None, object_name=None):
|
|
|
|
if detail is None and object_name:
|
|
|
|
detail = self.default_detail % object_name
|
|
|
|
super(JMSObjectDoesNotExist, self).__init__(detail=detail, code=code)
|
2020-08-16 15:08:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SomeoneIsDoingThis(JMSException):
|
|
|
|
status_code = status.HTTP_409_CONFLICT
|
|
|
|
default_detail = _('Someone else is doing this. Please wait for complete')
|
|
|
|
|
|
|
|
|
|
|
|
class Timeout(JMSException):
|
|
|
|
status_code = status.HTTP_408_REQUEST_TIMEOUT
|
|
|
|
default_detail = _('Your request timeout')
|
|
|
|
|
|
|
|
|
|
|
|
class M2MReverseNotAllowed(JMSException):
|
|
|
|
status_code = status.HTTP_400_BAD_REQUEST
|
|
|
|
default_detail = _('M2M reverse not allowed')
|
2020-12-17 06:41:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReferencedByOthers(JMSException):
|
|
|
|
status_code = status.HTTP_400_BAD_REQUEST
|
|
|
|
default_code = 'referenced_by_others'
|
|
|
|
default_detail = _('Is referenced by other objects and cannot be deleted')
|
2021-04-25 08:22:38 +00:00
|
|
|
|
|
|
|
|
2022-07-04 03:29:39 +00:00
|
|
|
class UserConfirmRequired(JMSException):
|
|
|
|
def __init__(self, code=None):
|
|
|
|
detail = {
|
|
|
|
'code': code,
|
|
|
|
'detail': _('This action require confirm current user')
|
|
|
|
}
|
|
|
|
super().__init__(detail=detail, code=code)
|
2022-01-13 11:01:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UnexpectError(JMSException):
|
|
|
|
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
|
|
default_code = 'unexpect_error'
|
|
|
|
default_detail = _('Unexpect error occur')
|