diff options
| author | Sylvain Fankhauser <sylvain.fankhauser@liip.ch> | 2015-06-05 15:30:03 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-07-03 12:06:40 -0400 |
| commit | f5d5867a4a6aeddd58ff855a01ab4e438d938ac1 (patch) | |
| tree | 73ecdbab94868fbd360f057d4dc192781bebfae6 /django | |
| parent | b91a2a499fd562011fd275238924baa6002fb1f8 (diff) | |
Fixed #24877 -- Added middleware handling of response.render() errors.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/handlers/base.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 628f45df9e..5d25b89448 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -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 |
