use std::sync::Arc;
use thiserror::Error;
#[derive(Debug, Clone, Error)]
pub enum XboxError {
#[error("http request to {url} failed with status {status}")]
HttpStatus {
url: String,
status: reqwest::StatusCode,
},
#[error("network error: {0}")]
Network(Arc<reqwest::Error>),
#[error("no Xbox Live user found matching gamertag \"{0}\"")]
PersonNotFound(String),
#[cfg(feature = "legacy-password-login")]
#[error("failed to parse PPFT token from Microsoft login page")]
PpftNotFound,
#[cfg(feature = "legacy-password-login")]
#[error("failed to parse login post URL from Microsoft login page")]
PostUrlNotFound,
#[cfg(feature = "legacy-password-login")]
#[error("invalid Microsoft account username or password")]
InvalidCredentials,
#[cfg(feature = "legacy-password-login")]
#[error("login redirect response was missing a Location header")]
MissingRedirectLocation,
#[cfg(feature = "legacy-password-login")]
#[error("failed to extract access token from login redirect URL")]
RpsTicketNotFound,
}
impl From<reqwest::Error> for XboxError {
fn from(err: reqwest::Error) -> Self {
XboxError::Network(Arc::new(err))
}
}
impl XboxError {
pub fn is_unauthorized(&self) -> bool {
matches!(
self,
XboxError::HttpStatus { status, .. } if *status == reqwest::StatusCode::UNAUTHORIZED
)
}
}