mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
exception_handler: add codes for Http404 and PermissionDenied
This commit is contained in:
parent
27c382c98d
commit
c6dd9f8bfb
|
@ -81,14 +81,18 @@ def exception_handler(exc, context):
|
||||||
|
|
||||||
elif isinstance(exc, Http404):
|
elif isinstance(exc, Http404):
|
||||||
msg = _('Not found.')
|
msg = _('Not found.')
|
||||||
data = {'detail': six.text_type(msg)}
|
data = {'detail': {'non_field_errors': [{
|
||||||
|
'message': six.text_type(msg),
|
||||||
|
'code': 'not_found'}]}}
|
||||||
|
|
||||||
set_rollback()
|
set_rollback()
|
||||||
return Response(data, status=status.HTTP_404_NOT_FOUND)
|
return Response(data, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
elif isinstance(exc, PermissionDenied):
|
elif isinstance(exc, PermissionDenied):
|
||||||
msg = _('Permission denied.')
|
msg = _('Permission denied.')
|
||||||
data = {'detail': six.text_type(msg)}
|
data = {'detail': {'non_field_errors': [{
|
||||||
|
'message': six.text_type(msg),
|
||||||
|
'code': 'permission_denied'}]}}
|
||||||
|
|
||||||
set_rollback()
|
set_rollback()
|
||||||
return Response(data, status=status.HTTP_403_FORBIDDEN)
|
return Response(data, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user