cobble_core/error/
auth_error.rs

1/// Result with [`AuthError`](AuthError) as the error type.
2pub type AuthResult<T> = Result<T, AuthError>;
3
4/// An error that occurs during authentication.
5#[derive(Debug, thiserror::Error)]
6pub enum AuthError {
7    /// Failed to parse an URL
8    #[error("Failed to parse an URL")]
9    ParseUrl(oauth2::url::ParseError),
10    /// There was a problem configuring the request
11    #[error("There was a problem configuring the request: {0}")]
12    ConfigurationError(oauth2::ConfigurationError),
13    /// Error while requesting access token
14    #[error("Error while requesting access token: {0}")]
15    RequestTokenError(String),
16    /// Microsoft did not provide a refresh token
17    #[error("Microsoft did not provide a refresh token")]
18    NoRefreshToken,
19    /// Error while performing a web request
20    #[error("{0}")]
21    Request(reqwest::Error),
22    /// XBoxLive auth did not return a user hash
23    #[error("XBoxLive auth did not return a user hash")]
24    NoXblUserHash,
25    /// User is missing entitlements
26    #[error("User is missing entitlements")]
27    Unauthorized,
28}
29
30impl From<oauth2::url::ParseError> for AuthError {
31    fn from(err: oauth2::url::ParseError) -> Self {
32        Self::ParseUrl(err)
33    }
34}
35
36impl From<oauth2::ConfigurationError> for AuthError {
37    fn from(err: oauth2::ConfigurationError) -> Self {
38        Self::ConfigurationError(err)
39    }
40}
41
42impl From<reqwest::Error> for AuthError {
43    fn from(err: reqwest::Error) -> Self {
44        Self::Request(err)
45    }
46}