You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turns out Rocket will already respond with JSON when handling errors, providing the request supplies a Accept: application/json header. I've began work on a Fairing, DefaultJSON in feat/json-everywhere, which overrides the Accept header (or provides if it's not supplied) to application/json, which has the effect of making all error responses JSON whilst still letting the main application code respond in whatever it wants (i.e plain/text for the health-check and YAML for the docs).
There is however, the 406 HTTP status code, which is explicitly for when the server cannot respond with any of the MIME types specified in Accept headers, so we couldonly return with JSON and respond with a 406 if the client won't accept it, however the issue here is that Rocket currently doesn't support letting Fairings terminate or respond to requests in on_request (see the overview for Fairings in the Rocket docs. This is something planned for v0.6 of Rocket, but it's currently blocked with some hacky workarounds suggested (see rwf2/Rocket#749).
Most error HTTP status returned from the API have a non-JSON body. Everything should respond with JSON since it's a RESTful API!
The text was updated successfully, but these errors were encountered: