Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
382ea770
Commit
382ea770
authored
Aug 18, 2016
by
Tom Christie
Committed by
GitHub
Aug 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve debug error handling (#4416)
parent
b76984d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
rest_framework/request.py
+5
-0
rest_framework/views.py
+10
-10
No files found.
rest_framework/request.py
View file @
382ea770
...
@@ -391,3 +391,8 @@ class Request(object):
...
@@ -391,3 +391,8 @@ class Request(object):
'`request.QUERY_PARAMS` has been deprecated in favor of `request.query_params` '
'`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.'
'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
rest_framework/views.py
View file @
382ea770
...
@@ -3,17 +3,14 @@ Provides an APIView class that is the base of all views in REST framework.
...
@@ -3,17 +3,14 @@ Provides an APIView class that is the base of all views in REST framework.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
sys
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.db
import
models
from
django.db
import
models
from
django.http
import
Http404
from
django.http
import
Http404
from
django.http.response
import
HttpResponse
,
HttpResponse
Base
from
django.http.response
import
HttpResponseBase
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.encoding
import
smart_text
from
django.utils.encoding
import
smart_text
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views
import
debug
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic
import
View
from
django.views.generic
import
View
...
@@ -95,11 +92,6 @@ def exception_handler(exc, context):
...
@@ -95,11 +92,6 @@ def exception_handler(exc, context):
set_rollback
()
set_rollback
()
return
Response
(
data
,
status
=
status
.
HTTP_403_FORBIDDEN
)
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
return
None
...
@@ -439,11 +431,19 @@ class APIView(View):
...
@@ -439,11 +431,19 @@ class APIView(View):
response
=
exception_handler
(
exc
,
context
)
response
=
exception_handler
(
exc
,
context
)
if
response
is
None
:
if
response
is
None
:
raise
self
.
raise_uncaught_exception
(
exc
)
response
.
exception
=
True
response
.
exception
=
True
return
response
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
# Note: Views are made CSRF exempt from within `as_view` as to prevent
# accidental removal of this exemption in cases where `dispatch` needs to
# accidental removal of this exemption in cases where `dispatch` needs to
# be overridden.
# be overridden.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment