Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
f5d5867a
Kaydet (Commit)
f5d5867a
authored
Haz 05, 2015
tarafından
Sylvain Fankhauser
Kaydeden (comit)
Tim Graham
Tem 03, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24877 -- Added middleware handling of response.render() errors.
üst
b91a2a49
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
10 deletions
+47
-10
base.py
django/core/handlers/base.py
+17
-10
1.9.txt
docs/releases/1.9.txt
+3
-0
middleware.py
tests/middleware_exceptions/middleware.py
+8
-0
tests.py
tests/middleware_exceptions/tests.py
+10
-0
urls.py
tests/middleware_exceptions/urls.py
+1
-0
views.py
tests/middleware_exceptions/views.py
+8
-0
No files found.
django/core/handlers/base.py
Dosyayı görüntüle @
f5d5867a
...
...
@@ -146,15 +146,7 @@ class BaseHandler(object):
try
:
response
=
wrapped_callback
(
request
,
*
callback_args
,
**
callback_kwargs
)
except
Exception
as
e
:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for
middleware_method
in
self
.
_exception_middleware
:
response
=
middleware_method
(
request
,
e
)
if
response
:
break
if
response
is
None
:
raise
response
=
self
.
process_exception_by_middleware
(
e
,
request
)
# Complain if the view returned None (a common error).
if
response
is
None
:
...
...
@@ -176,7 +168,11 @@ class BaseHandler(object):
"
%
s.process_template_response didn't return an "
"HttpResponse object. It returned None instead."
%
(
middleware_method
.
__self__
.
__class__
.
__name__
))
response
=
response
.
render
()
try
:
response
=
response
.
render
()
except
Exception
as
e
:
response
=
self
.
process_exception_by_middleware
(
e
,
request
)
response_is_rendered
=
True
except
http
.
Http404
as
exc
:
...
...
@@ -257,6 +253,17 @@ class BaseHandler(object):
return
response
def
process_exception_by_middleware
(
self
,
exception
,
request
):
"""
Pass the exception to the exception middleware. If no middleware
return a response for this exception, raise it.
"""
for
middleware_method
in
self
.
_exception_middleware
:
response
=
middleware_method
(
request
,
exception
)
if
response
:
return
response
raise
def
handle_uncaught_exception
(
self
,
request
,
resolver
,
exc_info
):
"""
Processing for any otherwise uncaught exceptions (those that will
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
f5d5867a
...
...
@@ -480,6 +480,9 @@ Requests and Responses
:class:`~django.template.response.TemplateResponse`, commonly used with
class-based views.
* Exceptions raised by the ``render()`` method are now passed to the
``process_exception()`` method of each middleware.
* Request middleware can now set :attr:`HttpRequest.urlconf
<django.http.HttpRequest.urlconf>` to ``None`` to revert any changes made
by previous middleware and return to using the :setting:`ROOT_URLCONF`.
...
...
tests/middleware_exceptions/middleware.py
0 → 100644
Dosyayı görüntüle @
f5d5867a
from
__future__
import
unicode_literals
from
django.http
import
HttpResponse
class
ProcessExceptionMiddleware
(
object
):
def
process_exception
(
self
,
request
,
exception
):
return
HttpResponse
(
'Exception caught'
)
tests/middleware_exceptions/tests.py
Dosyayı görüntüle @
f5d5867a
...
...
@@ -486,6 +486,16 @@ class MiddlewareTests(BaseMiddlewareExceptionTest):
# Check that the right middleware methods have been invoked
self
.
assert_middleware_usage
(
middleware
,
True
,
True
,
True
,
True
,
False
)
@override_settings
(
MIDDLEWARE_CLASSES
=
[
'middleware_exceptions.middleware.ProcessExceptionMiddleware'
],
)
def
test_exception_in_render_passed_to_process_exception
(
self
):
# Repopulate the list of middlewares since it's already been populated
# by setUp() before the MIDDLEWARE_CLASSES setting got overridden
self
.
client
.
handler
.
load_middleware
()
response
=
self
.
client
.
get
(
'/middleware_exceptions/exception_in_render/'
)
self
.
assertEqual
(
response
.
content
,
b
'Exception caught'
)
class
BadMiddlewareTests
(
BaseMiddlewareExceptionTest
):
...
...
tests/middleware_exceptions/urls.py
Dosyayı görüntüle @
f5d5867a
...
...
@@ -8,6 +8,7 @@ urlpatterns = [
url
(
r'^middleware_exceptions/error/$'
,
views
.
server_error
),
url
(
r'^middleware_exceptions/null_view/$'
,
views
.
null_view
),
url
(
r'^middleware_exceptions/permission_denied/$'
,
views
.
permission_denied
),
url
(
r'^middleware_exceptions/exception_in_render/$'
,
views
.
exception_in_render
),
url
(
r'^middleware_exceptions/template_response/$'
,
views
.
template_response
),
url
(
r'^middleware_exceptions/template_response_error/$'
,
views
.
template_response_error
),
...
...
tests/middleware_exceptions/views.py
Dosyayı görüntüle @
f5d5867a
...
...
@@ -32,3 +32,11 @@ def null_view(request):
def
permission_denied
(
request
):
raise
PermissionDenied
()
def
exception_in_render
(
request
):
class
CustomHttpResponse
(
http
.
HttpResponse
):
def
render
(
self
):
raise
Exception
(
'Exception in HttpResponse.render()'
)
return
CustomHttpResponse
(
'Error'
)
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