renegade_sdk/external_match_client/
error.rs1use reqwest::StatusCode;
4
5use crate::http::RelayerHttpClientError;
6
7#[derive(Debug, thiserror::Error)]
9pub enum ExternalMatchClientError {
10 #[error(
12 "error while requesting external match: status={}, message={1}",
13 .0.as_ref().map(ToString::to_string).unwrap_or_else(|| "none".to_string())
14 )]
15 Http(Option<StatusCode>, String),
16 #[error("the api key is invalid")]
18 InvalidApiKey,
19 #[error("the api secret is invalid")]
21 InvalidApiSecret,
22 #[error("invalid modification to a malleable match: {0}")]
24 InvalidModification(String),
25 #[error("invalid order: {0}")]
27 InvalidOrder(String),
28 #[error("error deserializing a response: {0}")]
30 Deserialize(String),
31}
32
33impl ExternalMatchClientError {
34 #[allow(clippy::needless_pass_by_value)]
36 pub(crate) fn http<T: ToString>(status: StatusCode, msg: T) -> Self {
37 Self::Http(Some(status), msg.to_string())
38 }
39
40 #[allow(clippy::needless_pass_by_value)]
42 pub(crate) fn invalid_modification<T: ToString>(msg: T) -> Self {
43 Self::InvalidModification(msg.to_string())
44 }
45
46 #[allow(clippy::needless_pass_by_value)]
48 pub(crate) fn invalid_order<T: ToString>(msg: T) -> Self {
49 Self::InvalidOrder(msg.to_string())
50 }
51
52 #[allow(clippy::needless_pass_by_value)]
54 pub(crate) fn deserialize<T: ToString>(msg: T) -> Self {
55 Self::Deserialize(msg.to_string())
56 }
57}
58
59impl From<reqwest::Error> for ExternalMatchClientError {
60 fn from(err: reqwest::Error) -> Self {
61 Self::Http(None, err.to_string())
62 }
63}
64
65impl From<RelayerHttpClientError> for ExternalMatchClientError {
66 fn from(err: RelayerHttpClientError) -> Self {
67 Self::Http(None, err.to_string())
68 }
69}