renegade_sdk/external_match_client/
error.rs1use reqwest::StatusCode;
4
5#[derive(Debug, thiserror::Error)]
7pub enum ExternalMatchClientError {
8 #[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 #[error("the api key is invalid")]
16 InvalidApiKey,
17 #[error("the api secret is invalid")]
19 InvalidApiSecret,
20 #[error("invalid modification to a malleable match: {0}")]
22 InvalidModification(String),
23 #[error("invalid order: {0}")]
25 InvalidOrder(String),
26 #[error("error deserializing a response: {0}")]
28 Deserialize(String),
29}
30
31impl ExternalMatchClientError {
32 pub(crate) fn http<T: ToString>(status: StatusCode, msg: T) -> Self {
34 Self::Http(Some(status), msg.to_string())
35 }
36
37 #[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 #[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 #[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}