8
8
from django .db import connection , models , transaction
9
9
from django .http import Http404
10
10
from django .http .response import HttpResponseBase
11
- from django .utils import six
12
11
from django .utils .cache import cc_delim_re , patch_vary_headers
13
12
from django .utils .encoding import smart_text
14
- from django .utils .translation import ugettext_lazy as _
15
13
from django .views .decorators .csrf import csrf_exempt
16
14
from django .views .generic import View
17
15
@@ -70,6 +68,11 @@ def exception_handler(exc, context):
70
68
Any unhandled exceptions may return `None`, which will cause a 500 error
71
69
to be raised.
72
70
"""
71
+ if isinstance (exc , Http404 ):
72
+ exc = exceptions .NotFound ()
73
+ elif isinstance (exc , PermissionDenied ):
74
+ exc = exceptions .PermissionDenied ()
75
+
73
76
if isinstance (exc , exceptions .APIException ):
74
77
headers = {}
75
78
if getattr (exc , 'auth_header' , None ):
@@ -85,20 +88,6 @@ def exception_handler(exc, context):
85
88
set_rollback ()
86
89
return Response (data , status = exc .status_code , headers = headers )
87
90
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
-
102
91
return None
103
92
104
93
0 commit comments