use std::fmt;
#[derive(Debug)]
pub enum RemoteSteamUserError {
Http(reqwest::Error),
Api { status: u16, message: String },
Json(serde_json::Error),
AllRetriesFailed,
NoUrls,
}
impl fmt::Display for RemoteSteamUserError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Http(e) => write!(f, "HTTP error: {}", e),
Self::Api { status, message } => write!(f, "API error (HTTP {}): {}", status, message),
Self::Json(e) => write!(f, "JSON error: {}", e),
Self::AllRetriesFailed => write!(f, "All retry attempts failed"),
Self::NoUrls => write!(f, "No server URLs provided"),
}
}
}
impl std::error::Error for RemoteSteamUserError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Http(e) => Some(e),
Self::Json(e) => Some(e),
_ => None,
}
}
}
impl From<reqwest::Error> for RemoteSteamUserError {
fn from(e: reqwest::Error) -> Self {
Self::Http(e)
}
}
impl From<serde_json::Error> for RemoteSteamUserError {
fn from(e: serde_json::Error) -> Self {
Self::Json(e)
}
}