From c6dd9f8bfb535b5671aa93983780e0abfaa5f471 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 31 Aug 2017 12:14:52 +0200 Subject: [PATCH] exception_handler: add codes for Http404 and PermissionDenied --- rest_framework/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rest_framework/views.py b/rest_framework/views.py index 8ec5f14ab..0cc4a2e8a 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -81,14 +81,18 @@ def exception_handler(exc, context): elif isinstance(exc, Http404): msg = _('Not found.') - data = {'detail': six.text_type(msg)} + data = {'detail': {'non_field_errors': [{ + 'message': six.text_type(msg), + 'code': 'not_found'}]}} set_rollback() return Response(data, status=status.HTTP_404_NOT_FOUND) elif isinstance(exc, PermissionDenied): msg = _('Permission denied.') - data = {'detail': six.text_type(msg)} + data = {'detail': {'non_field_errors': [{ + 'message': six.text_type(msg), + 'code': 'permission_denied'}]}} set_rollback() return Response(data, status=status.HTTP_403_FORBIDDEN)