From 2c05c63350affb360c6ffe36d9a7899da7e79e01 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 26 Jan 2023 19:07:27 -0800 Subject: [PATCH] error with body if not json --- .../src/bin/web3_proxy_cli/sentryd/compare.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs index 30de22fa..8417061c 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs @@ -60,16 +60,25 @@ pub async fn main( .context(format!("error querying block from {}", rpc)) .map_err(|x| error_builder.build(x))?; - // TODO: if !a.status().is_success() + if !a.status().is_success() { + return Err(anyhow::anyhow!( + "bad response from {}: {}", + rpc, + response.status(), + )); + } // TODO: capture response headers now in case of error. store them in the extra data on the pager duty alert let headers = format!("{:#?}", a.headers()); let a = a - .json::>>() + .text() .await - .context(format!("error parsing block from {}", rpc)) - .map_err(|x| error_builder.build(x))?; + .context(format!("failed parsing body from {}", rpc))?; + + let a: JsonRpcResponse> = serde_json::from_str(&body) + .context(format!("body: {}", body)) + .context(format!("failed parsing json from {}", rpc))?; let a = if let Some(block) = a.result { block @@ -204,7 +213,7 @@ async fn check_rpc( }); let response = client - .post(rpc.clone()) + .post(&rpc) .json(&block_by_hash_request) .send() .await