Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a48d21
fix a b0rked code example in the permissions section of api guide
wimglenn Aug 12, 2016
b508bc8
Merge pull request #4396 from wimglenn/docs_bugfix
jpadilla Aug 13, 2016
075a0bd
Fix template syntax error for `as_list_of_strings` (#4403)
jamesbeith Aug 15, 2016
785b206
Tweak doctsring. Closes #4404 [ci skip]
lovelydinosaur Aug 15, 2016
101fd29
Do not include uploads in request.POST (#4407)
lovelydinosaur Aug 15, 2016
e3f8d06
Include .action attribute on viewsets when generating schemas (#4408)
lovelydinosaur Aug 15, 2016
966330a
Replace utf8 character ' with its ascii counterpart, makes bdist_rpm.…
nevun Aug 17, 2016
b76984d
Allow custom CSRF_HEADER_NAME setting. (#4415)
lovelydinosaur Aug 18, 2016
382ea77
Improve debug error handling (#4416)
lovelydinosaur Aug 18, 2016
59ca61a
Add django-rest-framework-roles to third party packages in permission…
r1b Aug 19, 2016
e5b4498
Initial tests for API client
lovelydinosaur Aug 19, 2016
63342e8
Version 3.4.5 (#4421)
lovelydinosaur Aug 19, 2016
a335309
Add __str__ method to PKOnlyObject (#4423)
lovelydinosaur Aug 19, 2016
d540f02
Improve Create to show the original exception traceback (#3508)
orf Aug 19, 2016
c5e80e1
Merge branch 'master' into api-client
lovelydinosaur Aug 19, 2016
1a73c1c
Initial test cases for API client
lovelydinosaur Aug 19, 2016
e615f6d
Tests for API clients
lovelydinosaur Aug 22, 2016
341fa58
Support raw file uplaods with requests client / api client.
lovelydinosaur Aug 22, 2016
fe706eb
Tweak to tests for py3
lovelydinosaur Aug 22, 2016
b56e7d3
Upload and download support
lovelydinosaur Sep 9, 2016
b41ec30
Py3 compat
lovelydinosaur Sep 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve debug error handling (#4416)
  • Loading branch information
lovelydinosaur authored Aug 18, 2016
commit 382ea770b50a2615b4a8b99976d9f6a2a2093c71
5 changes: 5 additions & 0 deletions rest_framework/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,8 @@ def QUERY_PARAMS(self):
'`request.QUERY_PARAMS` has been deprecated in favor of `request.query_params` '
'since version 3.0, and has been fully removed as of version 3.2.'
)

def force_plaintext_errors(self, value):
# Hack to allow our exception handler to force choice of
# plaintext or html error responses.
self._request.is_ajax = lambda: value
20 changes: 10 additions & 10 deletions rest_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
"""
from __future__ import unicode_literals

import sys

from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db import models
from django.http import Http404
from django.http.response import HttpResponse, HttpResponseBase
from django.http.response import HttpResponseBase
from django.utils import six
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
from django.views import debug
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View

Expand Down Expand Up @@ -95,11 +92,6 @@ def exception_handler(exc, context):
set_rollback()
return Response(data, status=status.HTTP_403_FORBIDDEN)

# throw django's error page if debug is True
if settings.DEBUG:
exception_reporter = debug.ExceptionReporter(context.get('request'), *sys.exc_info())
return HttpResponse(exception_reporter.get_traceback_html(), status=500)

return None


Expand Down Expand Up @@ -439,11 +431,19 @@ def handle_exception(self, exc):
response = exception_handler(exc, context)

if response is None:
raise
self.raise_uncaught_exception(exc)

response.exception = True
return response

def raise_uncaught_exception(self, exc):
if settings.DEBUG:
request = self.request
renderer_format = getattr(request.accepted_renderer, 'format')
use_plaintext_traceback = renderer_format not in ('html', 'api', 'admin')
request.force_plaintext_errors(use_plaintext_traceback)
raise

# Note: Views are made CSRF exempt from within `as_view` as to prevent
# accidental removal of this exemption in cases where `dispatch` needs to
# be overridden.
Expand Down