1pub type Result<T> = std::result::Result<T, TxCacheError>;
5
6#[derive(thiserror::Error, Debug)]
10pub enum TxCacheError {
11 #[error("Transaction not found in cache")]
13 NotFound,
14 #[error("Request occurred during a slot that is not assigned to this builder")]
16 NotOurSlot,
17 #[error(transparent)]
19 Url(#[from] url::ParseError),
20
21 #[error("Error contacting TxCache API: {0}")]
23 Reqwest(reqwest::Error),
24
25 #[cfg(feature = "sse")]
27 #[cfg_attr(docsrs, doc(cfg(feature = "sse")))]
28 #[error("SSE stream error: {0}")]
29 Sse(eventsource_stream::EventStreamError<reqwest::Error>),
30
31 #[cfg(feature = "sse")]
33 #[cfg_attr(docsrs, doc(cfg(feature = "sse")))]
34 #[error("Failed to deserialize SSE event: {0}")]
35 Deserialization(serde_json::Error),
36}
37
38impl From<reqwest::Error> for TxCacheError {
39 fn from(err: reqwest::Error) -> Self {
40 match err.status() {
41 Some(reqwest::StatusCode::NOT_FOUND) => TxCacheError::NotFound,
42 Some(reqwest::StatusCode::FORBIDDEN) => TxCacheError::NotOurSlot,
43 _ => TxCacheError::Reqwest(err),
44 }
45 }
46}
47
48#[cfg(feature = "sse")]
49impl From<eventsource_stream::EventStreamError<reqwest::Error>> for TxCacheError {
50 fn from(err: eventsource_stream::EventStreamError<reqwest::Error>) -> Self {
51 Self::Sse(err)
52 }
53}
54
55#[cfg(feature = "sse")]
56impl From<serde_json::Error> for TxCacheError {
57 fn from(err: serde_json::Error) -> Self {
58 Self::Deserialization(err)
59 }
60}