Ticket #16367: response_middleware_exception_fix.diff

File response_middleware_exception_fix.diff, 1.2 KB (added by bob84123, 4 years ago)
  • django/core/handlers/base.py

     
    177177            for middleware_method in self._response_middleware:
    178178                response = middleware_method(request, response)
    179179            response = self.apply_response_fixes(request, response)
    180         except: # Any exception should be gathered and handled
     180        except Exception, e:
     181            # If a response middleware raised an exception, run it through
     182            # exception middleware, and if the exception middleware returns a
     183            # response, use that. Otherwise, reraise the exception.
     184            for middleware_method in self._exception_middleware:
     185                response = middleware_method(request, e)
     186                if response:
     187                    break
    181188            receivers = signals.got_request_exception.send(sender=self.__class__, request=request)
    182             response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
     189            if not response:
     190                response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
     191         
    183192
    184193        return response
    185194
Back to Top