Ticket #12909: 12909.diff

File 12909.diff, 1.8 KB (added by crucialfelix@…, 14 years ago)

django/core/handlers/wsgi.py handle exception thrown from middleware

  • django/core/handlers/wsgi.py

     
    1111from django.core.urlresolvers import set_script_prefix
    1212from django.utils import datastructures
    1313from django.utils.encoding import force_unicode, iri_to_uri
     14import sys
    1415
    1516# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    1617STATUS_CODE_TEXT = {
     
    220221
    221222    def __call__(self, environ, start_response):
    222223        from django.conf import settings
     224        from django.core import urlresolvers
    223225
    224226        # Set up middleware if needed. We couldn't do this earlier, because
    225227        # settings weren't available.
     
    241243                response = self.get_response(request)
    242244
    243245                # Apply response middleware
    244                 for middleware_method in self._response_middleware:
    245                     response = middleware_method(request, response)
     246                try:
     247                    for middleware_method in self._response_middleware:
     248                        response = middleware_method(request, response)
     249                except Exception,e:
     250                    if hasattr(request, "urlconf"):
     251                        urlconf = request.urlconf
     252                    else:
     253                        urlconf = settings.ROOT_URLCONF
     254                    urlresolvers.set_urlconf(urlconf)
     255                    resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
     256                    response = self.handle_uncaught_exception(request, resolver , sys.exc_info())
    246257                response = self.apply_response_fixes(request, response)
    247258        finally:
    248259            signals.request_finished.send(sender=self.__class__)
Back to Top