use reqwest::StatusCode;
#[derive(Debug, thiserror::Error)]
pub enum ExternalMatchClientError {
#[error(
"error while requesting external match: status={}, message={1}",
.0.as_ref().map(ToString::to_string).unwrap_or_else(|| "none".to_string())
)]
Http(Option<StatusCode>, String),
#[error("the api key is invalid")]
InvalidApiKey,
#[error("the api secret is invalid")]
InvalidApiSecret,
#[error("invalid modification to a malleable match: {0}")]
InvalidModification(String),
#[error("invalid order: {0}")]
InvalidOrder(String),
#[error("error deserializing a response: {0}")]
Deserialize(String),
}
impl ExternalMatchClientError {
pub(crate) fn http<T: ToString>(status: StatusCode, msg: T) -> Self {
Self::Http(Some(status), msg.to_string())
}
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn invalid_modification<T: ToString>(msg: T) -> Self {
Self::InvalidModification(msg.to_string())
}
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn invalid_order<T: ToString>(msg: T) -> Self {
Self::InvalidOrder(msg.to_string())
}
#[allow(clippy::needless_pass_by_value, unused)]
pub(crate) fn deserialize<T: ToString>(msg: T) -> Self {
Self::Deserialize(msg.to_string())
}
}
impl From<reqwest::Error> for ExternalMatchClientError {
fn from(err: reqwest::Error) -> Self {
Self::Http(None, err.to_string())
}
}