1use thiserror::Error;
2
3#[derive(Debug, Error)]
8pub enum BorsaError {
9 #[error("unsupported capability: {capability}")]
11 Unsupported {
12 capability: &'static str,
14 },
15
16 #[error("data issue: {0}")]
18 Data(String),
19
20 #[error("invalid argument: {0}")]
22 InvalidArg(String),
23
24 #[error("{connector} failed: {msg}")]
26 Connector {
27 connector: String,
29 msg: String,
31 },
32
33 #[error("unknown error: {0}")]
35 Other(String),
36
37 #[error("not found: {what}")]
39 NotFound {
40 what: String,
42 },
43
44 #[error("all providers failed: {0:?}")]
46 AllProvidersFailed(Vec<BorsaError>),
47
48 #[error("provider timed out: {capability} via {connector}")]
50 ProviderTimeout {
51 connector: String,
53 capability: &'static str,
55 },
56
57 #[error("request timed out: {capability}")]
59 RequestTimeout {
60 capability: &'static str,
62 },
63
64 #[error("all providers timed out: {capability}")]
66 AllProvidersTimedOut {
67 capability: &'static str,
69 },
70}
71
72impl BorsaError {
73 #[must_use]
75 pub const fn unsupported(cap: &'static str) -> Self {
76 Self::Unsupported { capability: cap }
77 }
78 pub fn connector(connector: impl Into<String>, msg: impl Into<String>) -> Self {
80 Self::Connector {
81 connector: connector.into(),
82 msg: msg.into(),
83 }
84 }
85
86 pub fn not_found(what: impl Into<String>) -> Self {
88 Self::NotFound { what: what.into() }
89 }
90
91 pub fn provider_timeout(connector: impl Into<String>, capability: &'static str) -> Self {
93 Self::ProviderTimeout {
94 connector: connector.into(),
95 capability,
96 }
97 }
98
99 #[must_use]
101 pub const fn request_timeout(capability: &'static str) -> Self {
102 Self::RequestTimeout { capability }
103 }
104}
105
106impl From<paft::Error> for BorsaError {
107 fn from(err: paft::Error) -> Self {
108 use paft::Error as E;
109 match err {
110 E::Money(_) => Self::Data(err.to_string()),
112 E::Core(_) | E::Domain(_) | E::Market(_) | E::MoneyParse(_) | E::Canonical(_) => {
114 Self::InvalidArg(err.to_string())
115 }
116 }
117 }
118}
119
120impl From<paft::market::MarketError> for BorsaError {
121 fn from(e: paft::market::MarketError) -> Self {
122 Self::InvalidArg(e.to_string())
123 }
124}
125
126impl From<paft::domain::DomainError> for BorsaError {
127 fn from(e: paft::domain::DomainError) -> Self {
128 Self::InvalidArg(e.to_string())
129 }
130}
131
132impl From<paft::core::PaftError> for BorsaError {
133 fn from(e: paft::core::PaftError) -> Self {
134 Self::InvalidArg(e.to_string())
135 }
136}
137
138impl From<paft::money::MoneyError> for BorsaError {
139 fn from(e: paft::money::MoneyError) -> Self {
140 Self::Data(e.to_string())
141 }
142}