Opened 4 years ago

Last modified 2 years ago

#24619 new New feature

Technical error responses (404 and 500) should return responses dependent on Accept header

Reported by: Marcin Nowak Owned by: nobody
Component: Core (Other) Version: master
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 (last modified by Tim Graham)

Technical error responses are used in DEBUG mode only and they aren't customizable.
In most cases they are resulting HTML output, but plain text only for AJAX-like requests (based on request.is_ajax() return value).

As a developer who is creating views/services non HTML-related (JSON, XML, etc as a response) I have huge problems with reading output from technical responses when error occurs. I'm getting in my console or shell HTML mixed with Javascript and CSS, which is hard to read. Text output from technical responses is hard-readable too, but better than HTML.

Technical responses should use some sort of output renderers registry based on Accept header. They should implement or use content type negotiation strategy and match against available renderers. Current HTML and text output can be mapped for text/html and text/plain types respectively. Also as a developer I need to extend registry of supported content types for my specific needs. For example - I need error 500 technical response returned as application/json content-type. Django can provide some built-in technical output renderers.

Optionally content-type negotiation functionality can be built as a standalone helper for common use.

Extracted from #24610

Change History (1)

comment:1 Changed 4 years ago by Tim Graham

Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Note: See TracTickets for help on using tickets.
Back to Top