8000 Modified exception handler to throw django error page in case of 500 … · encode/django-rest-framework@fa4ce50 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa4ce50

Browse files
akhilputhirytomchristie
authored andcommitted
Modified exception handler to throw django error page in case of 500 error (#4172)
Show Traceback HTML in browsable API
1 parent 378b04e commit fa4ce50

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rest_framework/views.py

Lines changed: 10 additions & 2 deletions
< 8000 th scope="col">Original file line number
Diff line numberDiff line change
@@ -3,13 +3,17 @@
33
"""
44
from __future__ import unicode_literals
55

6+
import sys
7+
8+
from django.conf import settings
69
from django.core.exceptions import PermissionDenied
710
from django.db import models
811
from django.http import Http404
9-
from django.http.response import HttpResponseBase
12+
from django.http.response import HttpResponse, HttpResponseBase
1013
from django.utils import six
1114
from django.utils.encoding import smart_text
1215
from django.utils.translation import ugettext_lazy as _
16+
from django.views import debug
1317
from django.views.decorators.csrf import csrf_exempt
1418
from django.views.generic import View
1519

@@ -91,7 +95,11 @@ def exception_handler(exc, context):
9195
set_rollback()
9296
return Response(data, status=status.HTTP_403_FORBIDDEN)
9397

94-
# Note: Unhandled exceptions will raise a 500 error.
98+
# throw django's error page if debug is True
99+
if settings.DEBUG:
100+
exception_reporter = debug.ExceptionReporter(context.get('request'), *sys.exc_info())
101+
return HttpResponse(exception_reporter.get_traceback_html(), status=500)
102+
95103
return None
96104

97105

0 commit comments

Comments
 (0)
0