1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum RobinhoodChainError {
6 #[error(
11 "RobinhoodChain: apiKey is required and must start with `msk_`. \
12 Get a free key at https://madeonsol.com/pricing"
13 )]
14 MissingApiKey,
15
16 #[error("Robinhood Chain API error ({status}): {message}")]
18 Api {
19 status: u16,
20 message: String,
21 body: serde_json::Value,
22 },
23
24 #[error("Robinhood Chain transport error: {0}")]
26 Transport(#[from] reqwest::Error),
27
28 #[error("Robinhood Chain JSON error: {0}")]
30 Json(#[from] serde_json::Error),
31
32 #[error("Robinhood Chain URL error: {0}")]
34 Url(#[from] url::ParseError),
35}
36
37impl RobinhoodChainError {
38 pub fn status(&self) -> Option<u16> {
40 match self {
41 RobinhoodChainError::Api { status, .. } => Some(*status),
42 _ => None,
43 }
44 }
45
46 pub fn body(&self) -> Option<&serde_json::Value> {
48 match self {
49 RobinhoodChainError::Api { body, .. } => Some(body),
50 _ => None,
51 }
52 }
53}
54
55pub type Result<T> = std::result::Result<T, RobinhoodChainError>;