88from django .db import connection , models , transaction
99from django .http import Http404
1010from django .http .response import HttpResponseBase
11- from django .utils import six
1211from django .utils .cache import cc_delim_re , patch_vary_headers
1312from django .utils .encoding import smart_text
14- from django .utils .translation import ugettext_lazy as _
1513from django .views .decorators .csrf import csrf_exempt
1614from django .views .generic import View
1715
@@ -70,6 +68,11 @@ def exception_handler(exc, context):
7068 Any unhandled exceptions may return `None`, which will cause a 500 error
7169 to be raised.
7270 """
71+ if isinstance (exc , Http404 ):
72+ exc = exceptions .NotFound ()
73+ elif isinstance (exc , PermissionDenied ):
74+ exc = exceptions .PermissionDenied ()
75+
7376 if isinstance (exc , exceptions .APIException ):
7477 headers = {}
7578 if getattr (exc , 'auth_header' , None ):
@@ -85,20 +88,6 @@ def exception_handler(exc, context):
8588 set_rollback ()
8689 return Response (data , status = exc .status_code , headers = headers )
8790
88- elif isinstance (exc , Http404 ):
89- msg = _ ('Not found.' )
90- data = {'detail' : six .text_type (msg )}
91-
92- set_rollback ()
93- return Response (data , status = status .HTTP_404_NOT_FOUND )
94-
95- elif isinstance (exc , PermissionDenied ):
96- msg = _ ('Permission denied.' )
97- data = {'detail' : six .text_type (msg )}
98-
99- set_rollback ()
100- return Response (data , status = status .HTTP_403_FORBIDDEN )
101-
10291 return None
10392
10493
0 commit comments