summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-09-12 10:53:47 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-09-12 10:53:47 +0200
commit2bc13231538133ad452b1b72ac4bbfe67235df02 (patch)
treedf85d3a7760214d16e4a40c286a2b579d4b76dee /mullvad-daemon/src
parentbf85a72a067389abfee4498a07b3a2d0fa8443eb (diff)
parent242d2c685a081e52ab3536be54554d3bb95449d5 (diff)
downloadmullvadvpn-2bc13231538133ad452b1b72ac4bbfe67235df02.tar.xz
mullvadvpn-2bc13231538133ad452b1b72ac4bbfe67235df02.zip
Merge branch 'more-detailed-rpc-errors'
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/management_interface.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index ab1c4deee9..bca4f68f13 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -1,5 +1,6 @@
use error_chain;
+use error_chain::ChainedError;
use jsonrpc_client_core;
use jsonrpc_core::{Error, ErrorCode, Metadata};
use jsonrpc_core::futures::{Future, future, sync};
@@ -246,6 +247,24 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterface<T> {
.map_err(|_| Error::internal_error())
)
}
+
+ /// Converts the given error to an error that can be given to the caller of the API.
+ /// Will let any actual RPC error through as is, any other error is changed to an internal
+ /// error.
+ fn map_rpc_error(error: jsonrpc_client_core::Error) -> Error {
+ match error.kind() {
+ &jsonrpc_client_core::ErrorKind::JsonRpcError(ref rpc_error) => {
+ // We have to manually copy the error since we have different
+ // versions of the jsonrpc_core library at the moment.
+ Error {
+ code: ErrorCode::from(rpc_error.code.code()),
+ message: rpc_error.message.clone(),
+ data: rpc_error.data.clone(),
+ }
+ }
+ _ => Error::internal_error(),
+ }
+ }
}
impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for ManagementInterface<T> {
@@ -256,7 +275,19 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem
let (tx, rx) = sync::oneshot::channel();
let future = self.send_command_to_daemon(TunnelCommand::GetAccountData(tx, account_token))
.and_then(|_| rx.map_err(|_| Error::internal_error()))
- .and_then(|rpc_future| rpc_future.map_err(|_| Error::internal_error()));
+ .and_then(
+ |rpc_future| {
+ rpc_future.map_err(
+ |error: jsonrpc_client_core::Error| {
+ error!(
+ "Unable to get account data from master: {}",
+ error.display_chain()
+ );
+ Self::map_rpc_error(error)
+ },
+ )
+ },
+ );
Box::new(future)
}