Add exceptions hierarchy.
parent
c93baac1c3
commit
7e3f1b88f5
|
@ -4,20 +4,58 @@ from rest_framework import exceptions
|
|||
from rest_framework import status
|
||||
|
||||
|
||||
class PermissionDenied(exceptions.PermissionDenied):
|
||||
pass
|
||||
|
||||
|
||||
class NotFound(exceptions.APIException):
|
||||
status_code = status.HTTP_404_NOT_FOUND
|
||||
default_detail = "Not found"
|
||||
class BaseException(exceptions.APIException):
|
||||
status_code = status.HTTP_400_BAD_REQUEST
|
||||
default_detail = 'Unexpected error'
|
||||
|
||||
def __init__(self, detail=None):
|
||||
self.detail = detail or self.default_detail
|
||||
|
||||
|
||||
class BadRequest(exceptions.ParseError):
|
||||
default_detail = "Bad request"
|
||||
class NotFound(BaseException):
|
||||
"""
|
||||
Exception used for not found objects.
|
||||
"""
|
||||
|
||||
status_code = status.HTTP_404_NOT_FOUND
|
||||
default_detail = 'Not found.'
|
||||
|
||||
|
||||
__all__ = ["PermissionDenied", "NotFound", "BadRequest"]
|
||||
class BadRequest(BaseException):
|
||||
"""
|
||||
Exception used on bad arguments detected
|
||||
on api view.
|
||||
"""
|
||||
default_detail = 'Wrong arguments.'
|
||||
|
||||
|
||||
class WrongArguments(BaseException):
|
||||
"""
|
||||
Exception used on bad arguments detected
|
||||
on service. This is same as `BadRequest`.
|
||||
"""
|
||||
default_detail = 'Wrong arguments.'
|
||||
|
||||
|
||||
class PermissionDenied(exceptions.PermissionDenied):
|
||||
"""
|
||||
Compatibility subclass of restframework `PermissionDenied`
|
||||
exception.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class InternalError(BaseException):
|
||||
"""
|
||||
Exception for internal errors.
|
||||
"""
|
||||
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
default_detail = "Internal server error"
|
||||
|
||||
|
||||
class NotAuthenticated(exceptions.NotAuthenticated):
|
||||
"""
|
||||
Compatibility subclass of restframework `NotAuthenticated`
|
||||
exception.
|
||||
"""
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue