-
Notifications
You must be signed in to change notification settings - Fork 92
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
Let oxide_auth_rocket::OAuthFailure
be a #[non_exhaustive]
enum
#118
Comments
When implementing the type, I wasn't really expecting it to be used for storing an error type. It's mostly a wrapper that implements |
I don't really require it to be stored, I just realized that I probably worded the op a bit strangely. I'm currently trying to implement match protection {
Ok(_grant) => {
Outcome::Success(())
},
Err(e) => {
match e {
Ok(ok) => {
let resp: RocketResponse = ok.into();
Outcome::Failure((resp.status(), resp))
},
Err(err) => {
// Logic here is the same as in oxide_auth_rocket/failure.rs, the Responder
// impl for OAuthFailure
if let Some(oauth) = err.oauth() {
match oauth {
OAuthError::BadRequest | OAuthError::DenySilently => {
Outcome::Failure((Status::BadRequest, RocketResponse::new()))
},
OAuthError::PrimitiveError => {
Outcome::Failure((Status::InternalServerError, RocketResponse::new()))
}
}
} else if let Some(_web) = err.web() {
Outcome::Failure((Status::BadRequest, RocketResponse::new()))
} else {
unreachable!();
}
},
}
}
} To me it would make more sense to match on
Does that make sense? I guess a follow-up question is if there's a better way to handle this in general, currently I've just copied the implementation details from the |
If you want to treat use a different error that's fine. You only have to implement the |
I see, thanks for the info! I guess you do not want to replace |
Hm, I hadn't considered that |
Project Improvement
Currently
oxide_auth_rocket::OAuthFailure
is a struct with a private inner fieldKind
which one can retrieve variants from via theoauth()
andweb()
methods. If you want to roll your own error type (sinceOAuthFailure
is not stable) you have to do some cumbersome matching that feels a bit un-rusty:Turning the failure type into a non-exhaustive enum would allow users to match on the enum instead of having to call functions while still allowing the project to add new failure modes.
Other context
It just feels like a more ergonomic interface to use.
Tracking pull request
The text was updated successfully, but these errors were encountered: