Opened 14 years ago
Closed 14 years ago
#13850 closed (invalid)
Make handle_uncaught_exception() more easily patch-able
Reported by: | Leonid Grinberg | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | mail, unhandlederror, http500 | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a 500 error happens that is not handled by any middleware, etc., Django goes into core.handlers.base.handle_uncaught_exception, which, if settings.DEBUG is set to False, generates a simple email that contains the traceback and request data and sends it to the admins specified in settings.py. This behavior is not configurable, and in particular there is no easy way to customize what the contents of the email is. The best one can hope to do is to subclass or monkey-patch BaseHandler.
It would be nice for this function to use a helper method of BaseHandler that takes the same information (request and exc_info) and returns the (subject, message) tuple. Then, applications that would like more detailed error emails can simply replace this function with whatever they want. The attached patch does this.
Attachments (1)
Change History (4)
by , 14 years ago
Attachment: | uncaught-exception-email.patch added |
---|
follow-up: 2 comment:1 by , 14 years ago
comment:2 by , 14 years ago
Replying to berto:
Once this patch is applied where do you customize the make_uncaught_exception_email() function?
You redefine it in settings.py. It's ugly, but it's strictly better than what one would have to do now, which is to redefine the entire handle_uncaught_exception() function.
comment:3 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Django 1.3's logging framework allows you to configure what's invoked when there's an uncaught exception. E.g.,
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'foo.FooLogHandler' } }, 'loggers': { 'django.request':{ 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } }
Where foo.FooLogHandler
is your own handler that fires off an email in the format you prefer.
Once this patch is applied where do you customize the make_uncaught_exception_email() function?