Exception reporter returns text/html response when X-Requested-With is set.
Prior to 3.1, exceptions encountered during an AJAX-style request were returned as text/plain content (see ticket #10841). Ticket #30752 introduced a new ExceptionReporter subclass feature in 3.1, which appears to have changed the out-of-the-box behavior. Now all exceptions return text/html content, regardless of whether they occur in an AJAX-style request or not. This makes parsing errors that occur from an AJAX-style request a lot harder. I was unable to find any details on this nuance in the 3.1 documentation.
Change History
(2)
Cc: |
Claude Paroz added
|
Resolution: |
→ wontfix
|
Status: |
new → closed
|
Summary: |
Exceptions always return text/html response, even in AJAX case → Exceptions always return text/html response, even in AJAX case.
|
Summary: |
Exceptions always return text/html response, even in AJAX case. → Exception reporter returns text/html response when X-Requested-With is set.
|
It's not related with #30752. This is caused by #30997 (see 7fa0fa45c5786619409036c5adce52ff6189b0ac). We deprecated
is_ajax()
which uses the non-standardX-Requested-With
header and removed it's usage from Django. The logic behind the decision to return a different exception content is now based on theAccept
HTTP header, you should set it toapplication/json
.