aboutsummaryrefslogtreecommitdiff
path: root/src/rpc_client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc_client.rs')
-rw-r--r--src/rpc_client.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/rpc_client.rs b/src/rpc_client.rs
index 95288269..35debb53 100644
--- a/src/rpc_client.rs
+++ b/src/rpc_client.rs
@@ -9,7 +9,7 @@ use futures::stream::futures_unordered::FuturesUnordered;
use futures::stream::StreamExt;
use futures_util::future::FutureExt;
use hyper::client::{Client, HttpConnector};
-use hyper::{Body, Method, Request, StatusCode};
+use hyper::{Body, Method, Request};
use tokio::sync::watch;
use crate::background::BackgroundRunner;
@@ -228,12 +228,14 @@ impl RpcHttpClient {
e
})?;
- if resp.status() == StatusCode::OK {
- let body = hyper::body::to_bytes(resp.into_body()).await?;
- let msg = rmp_serde::decode::from_read::<_, Result<M, String>>(body.into_buf())?;
- msg.map_err(Error::RPCError)
- } else {
- Err(Error::RPCError(format!("Status code {}", resp.status())))
+ let status = resp.status();
+ let body = hyper::body::to_bytes(resp.into_body()).await?;
+ match rmp_serde::decode::from_read::<_, Result<M, String>>(body.into_buf()) {
+ Err(e) =>
+ Err(Error::RPCError(format!("Invalid reply"), status)),
+ Ok(Err(e)) =>
+ Err(Error::RPCError(e, status)),
+ Ok(Ok(x)) => Ok(x),
}
}
}