rest_framework.exceptions

Handled exceptions raised by REST framework.

In addition Django’s built in 403 and 404 exceptions are handled. (django.http.Http404 and django.core.exceptions.PermissionDenied)

Module Contents

_get_error_details(data, default_code=None)

Descend into a nested data structure, forcing any lazy translation strings or strings into ErrorDetail.

_get_codes(detail)
_get_full_details(detail)
class ErrorDetail

Bases:django.utils.six.text_type

A string-like object that can additionally have a code.

code
classmethod __new__(cls, string, code=None)
__eq__(self, other)
__ne__(self, other)
__repr__(self)
__hash__(self)
exception APIException(detail=None, code=None)

Bases:Exception

Base class for REST framework exceptions. Subclasses should provide .status_code and .default_detail properties.

status_code
default_detail
default_code = error
__str__(self)
get_codes(self)

Return only the code part of the error details.

Eg. {“name”: [“required”]}

get_full_details(self)

Return both the message & code parts of the error details.

Eg. {“name”: [{“message”: “This field is required.”, “code”: “required”}]}

exception ValidationError(detail=None, code=None)

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = invalid
exception ParseError

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = parse_error
exception AuthenticationFailed

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = authentication_failed
exception NotAuthenticated

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = not_authenticated
exception PermissionDenied

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = permission_denied
exception NotFound

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = not_found
exception MethodNotAllowed(method, detail=None, code=None)

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = method_not_allowed
exception NotAcceptable(detail=None, code=None, available_renderers=None)

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = not_acceptable
exception UnsupportedMediaType(media_type, detail=None, code=None)

Bases:rest_framework.exceptions.APIException

status_code
default_detail
default_code = unsupported_media_type
exception Throttled(wait=None, detail=None, code=None)

Bases:rest_framework.exceptions.APIException

status_code
default_detail
extra_detail_singular = Expected available in {wait} second.
extra_detail_plural = Expected available in {wait} seconds.
default_code = throttled
server_error(request, *args, **kwargs)

Generic 500 error handler.

bad_request(request, exception, *args, **kwargs)

Generic 400 error handler.