use cynic::http::CynicReqwestError;
#[derive(Debug)]
pub struct BlokliClientError(Box<ErrorKind>);
impl BlokliClientError {
pub fn kind(&self) -> &ErrorKind {
self.0.as_ref()
}
}
impl<T: Into<ErrorKind>> From<T> for BlokliClientError {
fn from(kind: T) -> Self {
Self(Box::new(kind.into()))
}
}
impl std::fmt::Display for BlokliClientError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::error::Error for BlokliClientError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self.0.as_ref())
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TrackingErrorKind {
Reverted,
Timeout,
SubmissionFailed,
ValidationFailed,
}
#[derive(Debug, thiserror::Error)]
pub enum ErrorKind {
#[error("no data returned from blokli unexpectedly")]
NoData,
#[error("remote blokli error: {kind} ({code}): {message}")]
BlokliError {
kind: &'static str,
code: String,
message: String,
},
#[error("invalid query input: {0}")]
InvalidInput(&'static str),
#[error("transaction tracking error: {0:?}")]
TrackingError(TrackingErrorKind),
#[error("data returned from blokli was unparseable")]
ParseError,
#[error("operation timed out at the client")]
Timeout,
#[error(transparent)]
Subscription(#[from] Box<eventsource_client::Error>),
#[error(transparent)]
UrlParse(#[from] url::ParseError),
#[error(transparent)]
Serialization(#[from] serde_json::Error),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error(transparent)]
Cynic(#[from] CynicReqwestError),
#[error(transparent)]
GraphQLError(#[from] cynic::GraphQlError),
#[cfg(feature = "testing")]
#[error(transparent)]
MockClientError(#[from] anyhow::Error),
}
#[cfg(feature = "testing")]
#[derive(Debug)]
pub struct InternalTxError(pub anyhow::Error);
#[cfg(feature = "testing")]
impl std::fmt::Display for InternalTxError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "internal TX error: {}", self.0)
}
}
#[cfg(feature = "testing")]
impl std::error::Error for InternalTxError {}