mirror of
https://github.com/django/django.git
synced 2025-06-07 20:49:11 +00:00
Refactored the HTTP 500 error response creation slightly. Provides the ability
for subclassing that piece of the processing path. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7928 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e7e4b8b0f7
commit
57bb10e6c4
@ -60,7 +60,6 @@ class BaseHandler(object):
|
|||||||
def get_response(self, request):
|
def get_response(self, request):
|
||||||
"Returns an HttpResponse object for the given HttpRequest"
|
"Returns an HttpResponse object for the given HttpRequest"
|
||||||
from django.core import exceptions, urlresolvers
|
from django.core import exceptions, urlresolvers
|
||||||
from django.core.mail import mail_admins
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
# Apply request middleware
|
# Apply request middleware
|
||||||
@ -122,10 +121,25 @@ class BaseHandler(object):
|
|||||||
|
|
||||||
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
|
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
|
||||||
raise
|
raise
|
||||||
elif settings.DEBUG:
|
return self.handle_uncaught_exception(request, resolver, exc_info)
|
||||||
|
|
||||||
|
def handle_uncaught_exception(self, request, resolver, exc_info):
|
||||||
|
"""
|
||||||
|
Processing for any otherwise uncaught exceptions (those that will
|
||||||
|
generate HTTP 500 responses). Can be overridden by subclasses who want
|
||||||
|
customised 500 handling.
|
||||||
|
|
||||||
|
Be *very* careful when overriding this because the error could be
|
||||||
|
caused by anything, so assuming something like the database is always
|
||||||
|
available would be an error.
|
||||||
|
"""
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.mail import mail_admins
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
from django.views import debug
|
from django.views import debug
|
||||||
return debug.technical_500_response(request, *exc_info)
|
return debug.technical_500_response(request, *exc_info)
|
||||||
else:
|
|
||||||
# When DEBUG is False, send an error message to the admins.
|
# When DEBUG is False, send an error message to the admins.
|
||||||
subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
|
subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user