-
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
Add response::ErrorResponse
and response::Result
#921
Conversation
This PR is similar to #911 but is simpler. Note that to achieve this simplicity, |
Can this be defined outside of axum-core, perhaps axum-extra? I would like to avoid expanding its API unless necessary. |
I'm pretty sure this can't be defined elsewhere, that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this, but if we decide to have it, it would be good do have more docs before merging.
I also wonder whether this should have a more specific name and/or whether there should be a Result
alias for it.
@jplatte I like the idea of a Can you tell me what additional docs you're looking for? |
This type makes for efficient use of the `?` operator when in a function with multiple return error types that all implement `IntoResponse`. Signed-off-by: Nathaniel McCallum <nathaniel@profian.com>
Before putting more effort into this, I think it makes sense to hear what David thinks again. In terms of docs, I am thinking of
|
@jplatte I already added an example in the |
I think it's looking good but I wanna play around with it a bit first to see. I'll do that during the weekend and let you know 😊 |
@davidpdrsn Any update? |
Not yet sorry. I'll let you know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer having a single error enum made with thiserror
and a manual implementation of IntoResponse
but for more adhoc stuff this might be nice.
I think the name Error
is too broad though, it also conflicts with axum::Error
. What about ErrorResponse
or ResponseForError
?
I like the suggestions of |
@jplatte @davidpdrsn I'll leave the decision up to you guys. However, |
The thing is that |
I'm updating this branch now in case you didn't notice. Hopefully I haven't overwritten anything you've done locally. You're right about std having multiple error types but I see that as kind of a special case, and honestly not very user friendly. I have heard from several users who have been confused about types with the same names, even though they were in different modules. The error types in std also implement |
My intuition is that less than half of all types used as an error in And while I agree there is a minor paper cut having two types with the same name in two different modules, I think the greater sin is diverging from ecosystem-wide convention. Anyone who learns Rust will hit the |
I think keeping the |
I don't care too much either way. |
I'm good with the above compromise. |
Sweet! I'm fixing up the PR now 😊 |
I am too. :) |
@davidpdrsn I'll let you fix the PR since you know how you want it. |
8a9d738
to
65b6793
Compare
I have rebased and made the discussed changes. |
@davidpdrsn I may have accidentally done a force push seconds after your push. |
Why 😭 I had made a bunch of nitpicky docs changes that I might just force push on top of yours then. |
@davidpdrsn I'm so sorry! Do you still have the commit locally? |
Yep! I'll look at it tomorrow 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response::ErrorResponse
and response::Result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick about the changelogs, otherwise looks great!
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
@npmccallum Thanks for working on this! |
This type makes for efficient use of the
?
operator when in a functionwith multiple return error types that all implement
IntoResponse
.Signed-off-by: Nathaniel McCallum nathaniel@profian.com