1use cynic::http::CynicReqwestError;
2
3#[derive(Debug)]
9pub struct BlokliClientError(Box<ErrorKind>);
10
11impl BlokliClientError {
12 pub fn kind(&self) -> &ErrorKind {
14 self.0.as_ref()
15 }
16}
17
18impl<T: Into<ErrorKind>> From<T> for BlokliClientError {
19 fn from(kind: T) -> Self {
20 Self(Box::new(kind.into()))
21 }
22}
23
24impl std::fmt::Display for BlokliClientError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 self.0.fmt(f)
27 }
28}
29
30impl std::error::Error for BlokliClientError {
31 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
32 Some(self.0.as_ref())
33 }
34}
35
36#[derive(Copy, Clone, Debug, PartialEq, Eq)]
38pub enum TrackingErrorKind {
39 Reverted,
41 Timeout,
43 SubmissionFailed,
45 ValidationFailed,
47}
48
49#[derive(Debug, thiserror::Error)]
51pub enum ErrorKind {
52 #[error("no data returned from blokli unexpectedly")]
54 NoData,
55 #[error("remote blokli error: {kind} ({code}): {message}")]
57 BlokliError {
58 kind: &'static str,
60 code: String,
62 message: String,
64 },
65 #[error("invalid query input: {0}")]
67 InvalidInput(&'static str),
68 #[error("transaction tracking error: {0:?}")]
70 TrackingError(TrackingErrorKind),
71 #[error("data returned from blokli was unparseable")]
73 ParseError,
74 #[error("operation timed out at the client")]
76 Timeout,
77 #[error(transparent)]
79 Subscription(#[from] Box<eventsource_client::Error>),
80 #[error(transparent)]
82 UrlParse(#[from] url::ParseError),
83 #[error(transparent)]
85 Serialization(#[from] serde_json::Error),
86 #[error(transparent)]
88 Reqwest(#[from] reqwest::Error),
89 #[error(transparent)]
91 Cynic(#[from] CynicReqwestError),
92 #[error(transparent)]
94 GraphQLError(#[from] cynic::GraphQlError),
95 #[cfg(feature = "testing")]
96 #[error(transparent)]
97 MockClientError(#[from] anyhow::Error),
98}
99
100#[cfg(feature = "testing")]
102#[derive(Debug)]
103pub struct InternalTxError(pub anyhow::Error);
104
105#[cfg(feature = "testing")]
106impl std::fmt::Display for InternalTxError {
107 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108 write!(f, "internal TX error: {}", self.0)
109 }
110}
111
112#[cfg(feature = "testing")]
113impl std::error::Error for InternalTxError {}