renegade_sdk/external_match_client/
error.rs

1//! The error type for the external match client
2
3use reqwest::StatusCode;
4
5/// An error that can occur when requesting an external match
6#[derive(Debug, thiserror::Error)]
7pub enum ExternalMatchClientError {
8    /// An error that can occur when requesting an external match
9    #[error(
10        "error while requesting external match: status={}, message={1}",
11        .0.as_ref().map(ToString::to_string).unwrap_or_else(|| "none".to_string())
12    )]
13    Http(Option<StatusCode>, String),
14    /// An error indicating that the api key is invalid
15    #[error("the api key is invalid")]
16    InvalidApiKey,
17    /// An error indicating that the api secret is invalid
18    #[error("the api secret is invalid")]
19    InvalidApiSecret,
20    /// An invalid modification to a malleable match
21    #[error("invalid modification to a malleable match: {0}")]
22    InvalidModification(String),
23    /// An error indicating that an order is invalid
24    #[error("invalid order: {0}")]
25    InvalidOrder(String),
26    /// An error deserializing a response
27    #[error("error deserializing a response: {0}")]
28    Deserialize(String),
29}
30
31impl ExternalMatchClientError {
32    /// Construct a new http error
33    pub(crate) fn http<T: ToString>(status: StatusCode, msg: T) -> Self {
34        Self::Http(Some(status), msg.to_string())
35    }
36
37    /// Construct a new invalid modification error
38    #[allow(clippy::needless_pass_by_value)]
39    pub(crate) fn invalid_modification<T: ToString>(msg: T) -> Self {
40        Self::InvalidModification(msg.to_string())
41    }
42
43    /// Construct a new invalid order error
44    #[allow(clippy::needless_pass_by_value)]
45    pub(crate) fn invalid_order<T: ToString>(msg: T) -> Self {
46        Self::InvalidOrder(msg.to_string())
47    }
48
49    /// Construct a new deserialize error
50    #[allow(clippy::needless_pass_by_value, unused)]
51    pub(crate) fn deserialize<T: ToString>(msg: T) -> Self {
52        Self::Deserialize(msg.to_string())
53    }
54}
55
56impl From<reqwest::Error> for ExternalMatchClientError {
57    fn from(err: reqwest::Error) -> Self {
58        Self::Http(None, err.to_string())
59    }
60}