aboutsummaryrefslogtreecommitdiff
path: root/src/rpc_client.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-19 17:15:48 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-19 17:15:48 +0200
commita6129d8626f5b87462b70eadbce2db08c9761cfd (patch)
tree7e0e0d348bc8f8672db57680f8aeedf9c6c03523 /src/rpc_client.rs
parent302502f4c10b4c1cd03d3b098b3e55a3f70054f2 (diff)
downloadgarage-a6129d8626f5b87462b70eadbce2db08c9761cfd.tar.gz
garage-a6129d8626f5b87462b70eadbce2db08c9761cfd.zip
Begin implement bucket management & admin commands
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),
}
}
}