Django's WSGI Handler should report exceptions to the start_response() callback
|Reported by:||James Henstridge||Owned by:||nobody|
|Cc:||James Henstridge, grahamd||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
The WSGI specification allows WSGI applications to pass an exception context to their start_response() callback if the response is being provided by an error handler.
This is quite useful for WSGI middleware that collects data about errors: they can log the problem and then pass on the error page generated by the application.
Unfortunately, Django's WSGI handler never seems to call start_response() with the third argument, preventing this sort of middleware from seeing errors in Django applications.
I think a solution to this would be something like:
- override handle_uncaught_exception() in WSGIHandler and make it stash exc_info somewhere (on the response object would be hacky but maybe workable).
- after call invokes get_response(), check for a captured exc_info value.
- if exc_info was captured, pass it to start_response()