use crate::base::generated::steam_language::EResult;
use crate::error::SteamError;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum AuthenticationException {
#[error("{message} with result {result:?}.")]
Failed {
message: String,
result: EResult,
},
#[error("{message}")]
Other {
message: String,
},
}
impl AuthenticationException {
pub fn failed(message: impl Into<String>, result: EResult) -> Self {
AuthenticationException::Failed {
message: message.into(),
result,
}
}
pub fn other(message: impl Into<String>) -> Self {
AuthenticationException::Other {
message: message.into(),
}
}
pub fn result(&self) -> Option<EResult> {
match self {
AuthenticationException::Failed { result, .. } => Some(*result),
AuthenticationException::Other { .. } => None,
}
}
}
impl From<AuthenticationException> for SteamError {
fn from(value: AuthenticationException) -> Self {
SteamError::Authentication(value.to_string())
}
}