-
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
Consider making it easier to construct ErrorResponse from a non-IntoResponse error #2671
Comments
Hi, is this still relevant? I found this and read up on the previous PR and would agree that the Proposal here would be a nice quality of life improvement for most users to safe some characters when using the library. Only aspect that im not sure of is the standing question about whether or not to log the error. |
Yeah, this is still relevant. I guess now that we have more maintainers / regular contributors, it would be nice to hear everybody's opinion though. @yanns @mladedav @SabrinaJewson how do you feel about this proposal, the alternatives and the open question of whether to log something? |
Another alternative is to expose a struct pub struct InternalServerError<T>(pub T);
impl<T: Display> IntoResponse for InternalServerError<T> {
// …
} Thus users would write Another thing to consider is whether it should use let mut body = format!("{error}");
let mut e: &dyn Error = &error;
while let Some(new_e) = e.source() {
e = new_e;
write!(body, ": {e}").unwrap();
} which would likely be more helpful for tracking down the root cause of the error. And given that |
I like the approach from @SabrinaJewson. Regarding the logging of errors I would also suggest that we don't implement it for now to keep consistency. Maybe open a separate Issue and discuss whether logging is desired and add it later? But that is just my humble opinion, I am open to any suggestions 😀 |
another addition based on the idea from @SabrinaJewson.
|
I think that showing the error at all is probably a leak; public-facing services should use other methods to ensure that 500 responses have no body (such as middleware or a custom error type). Showing the full chain makes it clear that this is to be used for development or internal services only. |
I've tried to put the discussed approach into a PR, would like suggestions on how to refine it further |
Feature Request
Motivation
People ask about short-circuiting from handler functions with non-
IntoResponse
errors somewhat frequently.We already have
ErrorResponse
inaxum::response
for returning different error types from a handler function conveniently. However, right now it is quite annoying to construct one from a non-IntoResponse
error type (see alternatives).Proposal
Add
to allow users to write
Alternatives
Expose a free function, same thing but less verbose
Do nothing. One can already do
Open questions
Should the
internal_server_error
function log the error as well?The text was updated successfully, but these errors were encountered: