1use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, OstiumError>;
9
10#[derive(Error, Debug)]
12pub enum OstiumError {
13 #[error("Network error: {0}")]
15 Network(String),
16
17 #[error("Contract error: {0}")]
19 Contract(String),
20
21 #[error("GraphQL error: {0}")]
23 GraphQL(String),
24
25 #[error("Configuration error: {0}")]
27 Config(String),
28
29 #[error("Validation error: {0}")]
31 Validation(String),
32
33 #[error("Wallet error: {0}")]
35 Wallet(String),
36
37 #[error("HTTP error: {0}")]
39 Http(#[from] reqwest::Error),
40
41 #[error("JSON error: {0}")]
43 Json(#[from] serde_json::Error),
44
45 #[error("Decimal error: {0}")]
47 Decimal(#[from] rust_decimal::Error),
48
49 #[error("Provider error: {0}")]
51 Provider(String),
52
53 #[error("{0}")]
55 Other(String),
56}
57
58impl OstiumError {
59 pub fn network<S: Into<String>>(msg: S) -> Self {
61 Self::Network(msg.into())
62 }
63
64 pub fn contract<S: Into<String>>(msg: S) -> Self {
66 Self::Contract(msg.into())
67 }
68
69 pub fn graphql<S: Into<String>>(msg: S) -> Self {
71 Self::GraphQL(msg.into())
72 }
73
74 pub fn config<S: Into<String>>(msg: S) -> Self {
76 Self::Config(msg.into())
77 }
78
79 pub fn validation<S: Into<String>>(msg: S) -> Self {
81 Self::Validation(msg.into())
82 }
83
84 pub fn wallet<S: Into<String>>(msg: S) -> Self {
86 Self::Wallet(msg.into())
87 }
88
89 pub fn provider<S: Into<String>>(msg: S) -> Self {
91 Self::Provider(msg.into())
92 }
93
94 pub fn other<S: Into<String>>(msg: S) -> Self {
96 Self::Other(msg.into())
97 }
98
99 pub fn conversion<S: Into<String>>(msg: S) -> Self {
101 Self::Other(format!("Conversion error: {}", msg.into()))
102 }
103
104 pub fn parsing<S: Into<String>>(msg: S) -> Self {
113 Self::Other(format!("Parsing error: {}", msg.into()))
114 }
115}