diff --git a/src/perms/tx_cache.rs b/src/perms/tx_cache.rs index 954bf3c..86890b7 100644 --- a/src/perms/tx_cache.rs +++ b/src/perms/tx_cache.rs @@ -1,11 +1,40 @@ use crate::perms::oauth::SharedToken; use serde::de::DeserializeOwned; use signet_tx_cache::{ - error::Result, + error::TxCacheError, types::{BundleKey, CacheObject, TxCacheBundle, TxCacheBundleResponse, TxCacheBundlesResponse}, TxCache, }; -use tracing::{instrument, warn}; +use thiserror::Error; +use tokio::sync::watch; +use tracing::instrument; + +/// Result type for [`BuilderTxCache`] operations. +pub type Result = std::result::Result; + +/// Errors that can occur when using the [`BuilderTxCache`] client. +#[derive(Debug, Error)] +pub enum BuilderTxCacheError { + /// Failed to retrieve the authentication token. + #[error("failed to retrieve auth token: {0}")] + TokenRetrieval(#[from] watch::error::RecvError), + + /// An error occurred during a TxCache operation. + #[error(transparent)] + TxCache(#[from] TxCacheError), +} + +impl From for BuilderTxCacheError { + fn from(err: reqwest::Error) -> Self { + BuilderTxCacheError::TxCache(TxCacheError::Reqwest(err)) + } +} + +impl From for BuilderTxCacheError { + fn from(err: url::ParseError) -> Self { + BuilderTxCacheError::TxCache(TxCacheError::Url(err)) + } +} const BUNDLES: &str = "bundles"; @@ -77,10 +106,7 @@ impl BuilderTxCache { T: DeserializeOwned + CacheObject, { let url = self.tx_cache.url().join(join)?; - let secret = self.token.secret().await.unwrap_or_else(|_| { - warn!("Failed to get token secret"); - "".to_string() - }); + let secret = self.token.secret().await?; self.tx_cache .client() diff --git a/tests/tx-cache.rs b/tests/tx-cache.rs index 7eca382..aa283e9 100644 --- a/tests/tx-cache.rs +++ b/tests/tx-cache.rs @@ -1,6 +1,9 @@ #![cfg(feature = "perms")] -use init4_bin_base::perms::{tx_cache::BuilderTxCache, SharedToken}; +use init4_bin_base::perms::{ + tx_cache::{BuilderTxCache, BuilderTxCacheError}, + SharedToken, +}; use signet_tx_cache::TxCacheError; const URL: &str = "https://transactions.parmigiana.signet.sh"; @@ -12,5 +15,8 @@ async fn test_tx_cache_get_bundles() { let bundles = client.get_bundles(None).await.unwrap_err(); - assert!(matches!(bundles, TxCacheError::NotOurSlot)); + assert!(matches!( + bundles, + BuilderTxCacheError::TxCache(TxCacheError::NotOurSlot) + )); }