Ticket #16674: wsgi-expose-exc-info.patch
File wsgi-expose-exc-info.patch, 2.0 KB (added by , 13 years ago) |
---|
-
django/core/handlers/wsgi.py
1 1 import sys 2 from threading import Lock 2 from threading import Lock, local 3 3 try: 4 4 from cStringIO import StringIO 5 5 except ImportError: … … 194 194 initLock = Lock() 195 195 request_class = WSGIRequest 196 196 197 def __init__(self): 198 super(WSGIHandler, self).__init__() 199 self._tls = local() 200 197 201 def __call__(self, environ, start_response): 198 202 from django.conf import settings 199 203 … … 215 219 216 220 set_script_prefix(base.get_script_name(environ)) 217 221 signals.request_started.send(sender=self.__class__) 222 self._tls.exc_info = None 218 223 try: 219 224 try: 220 225 request = self.request_class(environ) 221 226 except UnicodeDecodeError: 227 self._tls.exc_info = sys.exc_info() 222 228 logger.warning('Bad Request (UnicodeDecodeError)', 223 exc_info=s ys.exc_info(),229 exc_info=self._tls.exc_info, 224 230 extra={ 225 231 'status_code': 400, 226 232 } … … 239 245 response_headers = [(str(k), str(v)) for k, v in response.items()] 240 246 for c in response.cookies.values(): 241 247 response_headers.append(('Set-Cookie', str(c.output(header='')))) 242 start_response(status, response_headers) 248 try: 249 start_response(status, response_headers, self._tls.exc_info) 250 finally: 251 self._tls.exc_info = None 243 252 return response 244 253 254 def handle_uncaught_exception(self, request, resolver, exc_info): 255 # Capture the exception context so we can pass it back to 256 # __call__() 257 self._tls.exc_info = exc_info 258 try: 259 return super(WSGIHandler, self).handle_uncaught_exception( 260 request, resolver, exc_info) 261 finally: 262 exc_info = None