|
3 | 3 | """
|
4 | 4 | from __future__ import unicode_literals
|
5 | 5 |
|
6 |
| -import sys |
7 |
| - |
8 | 6 | from django.conf import settings
|
9 | 7 | from django.core.exceptions import PermissionDenied
|
10 | 8 | from django.db import models
|
11 | 9 | from django.http import Http404
|
12 |
| -from django.http.response import HttpResponse, HttpResponseBase |
| 10 | +from django.http.response import HttpResponseBase |
13 | 11 | from django.utils import six
|
14 | 12 | from django.utils.encoding import smart_text
|
15 | 13 | from django.utils.translation import ugettext_lazy as _
|
16 |
| -from django.views import debug |
17 | 14 | from django.views.decorators.csrf import csrf_exempt
|
18 | 15 | from django.views.generic import View
|
19 | 16 |
|
@@ -95,11 +92,6 @@ def exception_handler(exc, context):
|
95 | 92 | set_rollback()
|
96 | 93 | return Response(data, status=status.HTTP_403_FORBIDDEN)
|
97 | 94 |
|
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 |
| - |
103 | 95 | return None
|
104 | 96 |
|
105 | 97 |
|
@@ -439,11 +431,19 @@ def handle_exception(self, exc):
|
439 | 431 | response = exception_handler(exc, context)
|
440 | 432 |
|
441 | 433 | if response is None:
|
442 |
| - raise |
| 434 | + self.raise_uncaught_exception(exc) |
443 | 435 |
|
444 | 436 | response.exception = True
|
445 | 437 | return response
|
446 | 438 |
|
| 439 | + def raise_uncaught_exception(self, exc): |
| 440 | + if settings.DEBUG: |
| 441 | + request = self.request |
| 442 | + renderer_format = getattr(request.accepted_renderer, 'format') |
| 443 | + use_plaintext_traceback = renderer_format not in ('html', 'api', 'admin') |
| 444 | + request.force_plaintext_errors(use_plaintext_traceback) |
| 445 | + raise |
| 446 | + |
447 | 447 | # Note: Views are made CSRF exempt from within `as_view` as to prevent
|
448 | 448 | # accidental removal of this exemption in cases where `dispatch` needs to
|
449 | 449 | # be overridden.
|
|
0 commit comments