Ticket #20752: 20752_patch.diff
File 20752_patch.diff, 3.3 KB (added by , 11 years ago) |
---|
-
django/core/handlers/base.py
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 9679ae8..20a6a10 100644
a b class BaseHandler(object): 191 191 192 192 except: # Handle everything else. 193 193 # Get the exception info now, in case another exception is thrown later. 194 signals.got_request_exception.send(sender=self.__class__, request=request) 195 response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) 194 exc_info = sys.exc_info() 195 signal_responses = signals.got_request_exception.send_robust(sender=self.__class__, request=request) 196 for signal_response in signal_responses: 197 if isinstance(signal_response[1], Exception): 198 message = 'Base Handler Error %s: ' % signal_response[1] 199 logger.error(message+'%s', request.path, 200 exc_info=exc_info, 201 extra={ 202 'status_code': 500, 203 'request': request, 204 'error': signal_response[1] 205 } 206 ) 207 response = self.handle_uncaught_exception(request, resolver, exc_info) 196 208 197 209 try: 198 210 # Apply response middleware, regardless of the response -
tests/view_tests/tests/test_defaults.py
diff --git a/tests/view_tests/tests/test_defaults.py b/tests/view_tests/tests/test_defaults.py index d55ed53..7a74b0b 100644
a b 1 1 from __future__ import unicode_literals 2 2 3 import logging 4 5 from django.utils.six import StringIO 6 7 from django.core.signals import got_request_exception 8 from django.dispatch import receiver 3 9 from django.contrib.contenttypes.models import ContentType 10 4 11 from django.test import TestCase 5 12 from django.test.utils import (setup_test_template_loader, 6 restore_template_loaders, override_settings )13 restore_template_loaders, override_settings, patch_logger) 7 14 8 15 from ..models import Author, Article, UrlArticle 9 16 … … class DefaultsTests(TestCase): 33 40 34 41 def test_server_error(self): 35 42 "The server_error view raises a 500 status" 36 response = self.client.get('/views/server_error/') 37 self.assertEqual(response.status_code, 500) 43 with self.settings(DEBUG=True): 44 with patch_logger('django.request', 'error') as calls: 45 response = self.client.get('/views/server_error/') 46 self.assertEqual(response.status_code, 500) 47 self.assertEqual(len(calls), 1) 48 49 def test_server_error_with_handler_error(self): 50 """ 51 The server_error view raises a 500 status and while handling 52 the error, the next error is raised. 53 """ 54 55 @receiver(got_request_exception) 56 def handler(sender, **kwargs): 57 raise Exception('I am a Handler Error') 58 59 with self.settings(DEBUG=True): 60 with patch_logger('django.request', 'error') as calls: 61 response = self.client.get('/views/server_error/') 62 self.assertEqual(response.status_code, 500) 63 self.assertEqual(len(calls), 2) 38 64 39 65 def test_custom_templates(self): 40 66 """