Opened 9 years ago
Closed 5 years ago
#25167 closed New feature (duplicate)
Provide option to disable ajax text/plain response in technical_500_response
Reported by: | thenewguy | Owned by: | nobody |
---|---|---|---|
Component: | Error reporting | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Line in question: https://github.com/django/django/blob/master/django/views/debug.py#L89
Ticket #10841 from a long time ago made a change to return text/plain responses unconditionally when the request was made via ajax. It would be handy if this special casing of ajax requests could be disabled with a setting or something.
I just spent the last 45 minutes tracking down why the debug error pages were not rendering with styles on a new project I was basing on an older one that did not exhibit the issue.
Turns out I hit this before and the approach I came up with in the past was to monkey patch the handler and forcefully set ajax to false. Otherwise it seems like there is a lot of code to copy and also warnings in the source about writing error handlers. So I'd rather not, but I need to display the error messages during development...
Below is a sample of the monkey patch. It would probably be better to move the condition outside of the function and disable it when not in DEBUG mode. I am going to do that now I guess, but I figure it was worthwhile to raise the issue.
from django.conf import settings from django.core.handlers.base import BaseHandler handle_uncaught_exception = BaseHandler.handle_uncaught_exception def _handle_uncaught_exception_monkey_patch(self, request, resolver, exc_info): if settings.DEBUG: request.is_ajax = lambda: False return handle_uncaught_exception(self, request, resolver, exc_info) BaseHandler.handle_uncaught_exception = _handle_uncaught_exception_monkey_patch
Change History (2)
comment:1 by , 9 years ago
Component: | Uncategorized → Error reporting |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → New feature |
Version: | 1.8 → master |
comment:2 by , 5 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
#30752 (Django 3.1) allows providing a custom ExceptionReporter sublcass. (Exactly via the DEFAULT_EXCEPTION_REPORTER
setting Tim discusses above.) That will be the place to add the logic you need. (Make get_traceback_text()
a proxy to get_traceback_html()
being the first thing that comes to mind.)
I guess you use something like Chrome inspector which renders HTML just fine? It would be a nice feature, but I doubt adding a setting will be a popular solution.
There was an idea to replace
settings.DEFAULT_EXCEPTION_REPORTER_FILTER
with aDEFAULT_EXCEPTION_REPORTER
setting:Implementing that would likely make allow customizing this behavior easy.