Skip to content

Commit

Permalink
Better logging & instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 15, 2023
1 parent 1ee7d09 commit 4bdd0ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/tx-sitter-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ reqwest = "0.11.14"
serde = { version = "1.0.154", features = ["derive"] }
serde_json = "1.0.94"
strum = { version = "0.25", features = ["derive"] }
tracing = "0.1"
9 changes: 8 additions & 1 deletion crates/tx-sitter-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use data::{GetTxResponse, SendTxRequest, SendTxResponse, TxStatus};
use reqwest::Response;
use tracing::instrument;

pub mod data;

Expand Down Expand Up @@ -41,22 +42,28 @@ impl TxSitterClient {

async fn validate_response(response: Response) -> anyhow::Result<Response> {
if !response.status().is_success() {
let status = response.status();
let body = response.text().await?;

return Err(anyhow::anyhow!("{body}"));
return Err(anyhow::anyhow!(
"Response failed with status {status} - {body}"
));
}

Ok(response)
}

#[instrument(skip(self))]
pub async fn send_tx(&self, req: &SendTxRequest) -> anyhow::Result<SendTxResponse> {
self.json_post(&format!("{}/tx", self.url), req).await
}

#[instrument(skip(self))]
pub async fn get_tx(&self, tx_id: &str) -> anyhow::Result<GetTxResponse> {
self.json_get(&format!("{}/tx/{}", self.url, tx_id)).await
}

#[instrument(skip(self))]
pub async fn get_txs(&self, tx_status: Option<TxStatus>) -> anyhow::Result<Vec<GetTxResponse>> {
let mut url = format!("{}/txs", self.url);

Expand Down

0 comments on commit 4bdd0ee

Please sign in to comment.