falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.52k stars 946 forks source link

Serialize errors using response media handlers #2023

Closed vytas7 closed 1 month ago

vytas7 commented 2 years ago

Our default error serializer already supports rudimentary content negotiation between JSON, XML, or rendering no content at all.

We ought to extend this negotiation to all configured response media handlers, possibly somehow plugging JSON and XML as fallback if these are absent in the default handlers (JSON is there by default, but can be removed by the developer).

This has already been improved in Falcon 3.0 for JSON almost as defined here as part of https://github.com/falconry/falcon/pull/1768 by @CaselIT.

Implementation details TBD; this might be designed as a breaking change, or an iterative improvement, depending on how this feature is governed by configurable options, and what fallback mechanisms are available. If we handle this in a non-breaking way, it may make it into the 4.x series.

vytas7 commented 2 years ago

See also #2029