IntoResponse
implementation for (StatusCode, R) where R: IntoResponse
overrides error status codes and might be a footgun
#2287
Labels
Milestone
Bug Report
Version
(but I checked the source code for the latest version on docs.rs to notice this)
Crates
Description
I'm looking at the code in
async fn hello()
below.The general idea is: we're emitting a JSON payload with a custom status code.
But along the lines, something has gone wrong and the JSON serialisation fails (in this case: because the map has keys which are not strings and are not coerced into strings by
serde_json
).Had I just used
Json(map)
as the return value, then I'd get a 500 Internal Server Error response — very reasonable!However, instead I am getting the originally desired status code but with a text error message:
I find this a little bit unsettling and like it might turn out to be a bit of a footgun.
It's frankly not very likely with emitting Json (but not impossible) but when writing a custom
IntoResponse
to render a template or something like that, it seems quite reasonable to anticipate errors!On the other hand, I don't know how/if you can fix this with the current API surface. But it felt like it was worth documenting.
(I should note this is entirely academic only and hasn't caused me any trouble in a real project or anything, so of course don't waste too much time on me!)
The text was updated successfully, but these errors were encountered: