-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntoResponse
implementation for (StatusCode, R) where R: IntoResponse
overrides error status codes and might be a footgun
#2287
Comments
Hm yeah that is a bit of a footgun for sure. I think we could
Of these I'm leaning towards 2. Feels like it helps users "do the right thing" while letting you customize things if necessary. |
|
just brainstorming here: would it make sense to extract a |
It should work, but I'm uncertain whether it is better than what was proposed above. I guess it is in a way less magical, but we need two new traits (also for response parts), plus docs explaining which one to implement when. |
We could also change Note that in |
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: