error with body if not json

This commit is contained in:
Bryan Stitt 2023-01-26 19:07:27 -08:00
parent f9d3eb1e0d
commit 2c05c63350

@ -60,16 +60,25 @@ pub async fn main(
.context(format!("error querying block from {}", rpc)) .context(format!("error querying block from {}", rpc))
.map_err(|x| error_builder.build(x))?; .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 // 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 headers = format!("{:#?}", a.headers());
let a = a let a = a
.json::<JsonRpcResponse<Block<TxHash>>>() .text()
.await .await
.context(format!("error parsing block from {}", rpc)) .context(format!("failed parsing body from {}", rpc))?;
.map_err(|x| error_builder.build(x))?;
let a: JsonRpcResponse<Block<TxHash>> = serde_json::from_str(&body)
.context(format!("body: {}", body))
.context(format!("failed parsing json from {}", rpc))?;
let a = if let Some(block) = a.result { let a = if let Some(block) = a.result {
block block
@ -204,7 +213,7 @@ async fn check_rpc(
}); });
let response = client let response = client
.post(rpc.clone()) .post(&rpc)
.json(&block_by_hash_request) .json(&block_by_hash_request)
.send() .send()
.await .await