pub type Result<T> = std::result::Result<T, TxCacheError>;
#[derive(thiserror::Error, Debug)]
pub enum TxCacheError {
#[error("Transaction not found in cache")]
NotFound,
#[error("Request occurred during a slot that is not assigned to this builder")]
NotOurSlot,
#[error(transparent)]
Url(#[from] url::ParseError),
#[error("Error contacting TxCache API: {0}")]
Reqwest(reqwest::Error),
#[cfg(feature = "sse")]
#[cfg_attr(docsrs, doc(cfg(feature = "sse")))]
#[error("SSE stream error: {0}")]
Sse(eventsource_stream::EventStreamError<reqwest::Error>),
#[cfg(feature = "sse")]
#[cfg_attr(docsrs, doc(cfg(feature = "sse")))]
#[error("Failed to deserialize SSE event: {0}")]
Deserialization(serde_json::Error),
}
impl From<reqwest::Error> for TxCacheError {
fn from(err: reqwest::Error) -> Self {
match err.status() {
Some(reqwest::StatusCode::NOT_FOUND) => TxCacheError::NotFound,
Some(reqwest::StatusCode::FORBIDDEN) => TxCacheError::NotOurSlot,
_ => TxCacheError::Reqwest(err),
}
}
}
#[cfg(feature = "sse")]
impl From<eventsource_stream::EventStreamError<reqwest::Error>> for TxCacheError {
fn from(err: eventsource_stream::EventStreamError<reqwest::Error>) -> Self {
Self::Sse(err)
}
}
#[cfg(feature = "sse")]
impl From<serde_json::Error> for TxCacheError {
fn from(err: serde_json::Error) -> Self {
Self::Deserialization(err)
}
}