diff options
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index ade56f3abe..bca4f68f13 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -247,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> { @@ -255,28 +273,21 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem fn get_account_data(&self, account_token: AccountToken) -> BoxFuture<AccountData, Error> { trace!("get_account_data"); 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(|e: jsonrpc_client_core::Error| { - error!("Unable to get account data from master: {}", e.display_chain()); - match e.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(), - } - }) - }, - ); + 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: jsonrpc_client_core::Error| { + error!( + "Unable to get account data from master: {}", + error.display_chain() + ); + Self::map_rpc_error(error) + }, + ) + }, + ); Box::new(future) } |
