-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Type of rocket::request::Outcome is pub type Outcome = outcome::Outcome<S, (Status, E), ()> which seems weird #1629
Comments
Basically, I've been cleaning up code in our Rocket app, and I've had problems deciding on which way is best. I'm off the camp that if errors need a variable status code, it should be encoded in the error, mapped to a enum field, etc, by the responder. IE, instead of returning (401, SecurityError), or (403, SecurityError), SecurityError would have a enum field, Reason::Unauthorized/Notauntheticated, and the responder for the error would then be able to set 401/403 from that. There is no chance of accidentally retuirning (402, SecurityError) or (404, SecurityError) |
Looking at the Catchers, it appears the error is thrown away? So I assume it is logged, but the responder is not called? |
I think this comment can answer some of the questions: #1145 (comment) Specifically:
There is no requirement that request guard |
I find OutCome plays very poorly with Result. Any reason Result wasn't used with something like Result(ValueOrForward, Error) ValueOrForward would then be ValueOrForward::Value and ValueOrForward::Forward This would also make ? work again with early error return as opposed to needing try_outcome! |
Its potentially conceptually not as pure, but forward is not a failure, and it plays nice with a lot more of the existing rust infrastructure. |
I think all of your qualms would be solved with
Does this just mean you find it difficult to convert between the two? We can add methods to Edit: I should add that I've considered adjusting enum Outcome<T, E, F> {
Result(Result<T, E>),
Forward(F),
} Then there's the obvious |
I'm closing this out as there doesn't appear to be anything actionable here. |
What bothers me is it requires the Status code for the error to be decided up front, instead of at the end, when usually it can be derived from the error. This also means one FromRequest might decide on (403, ActualError), and another might decide on (500, ActualError ).
Usually I prefer encoding or deriving the status from a Error, or it's responder impl, or the global catcher.
Here, up front, the status must be decided immediately.
Hmm,
Looking here in the code
It seems the error state of Result is mapped to the success state of Outcome, which means the responder impl for Err, or the global handler would be used. So what is Outcome::Error for?
Reading the docs:
This seems like duplicated behavior between the default error Catcher and having errors implement Responder.
Is Outcome::Failure (status, error) intended as a shortcut?
The text was updated successfully, but these errors were encountered: