summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2020-05-14 10:51:32 +0200
committerLinus Färnstrand <linus@mullvad.net>2020-05-14 11:05:55 +0200
commitaa27e2155822b120644a9f02c5e6af40bb8feddb (patch)
treee55fea7eeef8d233af9795688bab58e336eec83e
parent410e79ecbd767c63a63ffd795cebe9e80fe74df5 (diff)
downloadmullvadvpn-aa27e2155822b120644a9f02c5e6af40bb8feddb.tar.xz
mullvadvpn-aa27e2155822b120644a9f02c5e6af40bb8feddb.zip
Exit with different exit codes in relay_list binary depending on error
-rw-r--r--mullvad-rpc/src/bin/relay_list.rs26
-rw-r--r--mullvad-rpc/src/rest.rs10
2 files changed, 24 insertions, 12 deletions
diff --git a/mullvad-rpc/src/bin/relay_list.rs b/mullvad-rpc/src/bin/relay_list.rs
index 4c76c27ac0..71c9c30917 100644
--- a/mullvad-rpc/src/bin/relay_list.rs
+++ b/mullvad-rpc/src/bin/relay_list.rs
@@ -1,16 +1,32 @@
/// Intended to be used to pre-load a relay list when creating an installer for the Mullvad VPN
/// app.
use futures01::future::Future;
-use mullvad_rpc::{MullvadRpcRuntime, RelayListProxy};
+use mullvad_rpc::{rest::Error as RestError, MullvadRpcRuntime, RelayListProxy};
+use std::process;
+use talpid_types::ErrorExt;
fn main() {
let mut runtime = MullvadRpcRuntime::new().expect("Failed to load runtime");
let relay_list_request = RelayListProxy::new(runtime.mullvad_rest_handle()).relay_list();
- let relay_list = relay_list_request
- .wait()
- .expect("Failed to fetch relay list");
-
+ let relay_list = match relay_list_request.wait() {
+ Ok(relay_list) => relay_list,
+ Err(RestError::TimeoutError(_)) => {
+ eprintln!("Request timed out");
+ process::exit(2);
+ }
+ Err(e @ RestError::DeserializeError(_)) => {
+ eprintln!(
+ "{}",
+ e.display_chain_with_msg("Failed to deserialize relay list")
+ );
+ process::exit(3);
+ }
+ Err(e) => {
+ eprintln!("{}", e.display_chain_with_msg("Failed to fetch relay list"));
+ process::exit(1);
+ }
+ };
println!("{}", serde_json::to_string_pretty(&relay_list).unwrap());
}
diff --git a/mullvad-rpc/src/rest.rs b/mullvad-rpc/src/rest.rs
index c93cccff15..451565a26c 100644
--- a/mullvad-rpc/src/rest.rs
+++ b/mullvad-rpc/src/rest.rs
@@ -44,8 +44,8 @@ pub enum Error {
#[error(display = "Timer error")]
TimerError(#[error(source)] tokio::time::Error),
- #[error(display = "Deserialization error")]
- DeserializationError,
+ #[error(display = "Failed to deserialize data")]
+ DeserializeError(#[error(source)] serde_json::Error),
#[error(display = "Failed to send request to rest client")]
SendError,
@@ -53,10 +53,6 @@ pub enum Error {
#[error(display = "Failed to receive response from rest client")]
ReceiveError,
- /// Serde error
- #[error(display = "Serialization error")]
- Serde(#[error(source)] serde_json::Error),
-
/// When the http status code of the response is not 200 OK.
#[error(display = "Http error. Status code {}", _0)]
ApiError(StatusCode, String),
@@ -513,7 +509,7 @@ pub async fn deserialize_body<T: serde::de::DeserializeOwned>(mut response: Resp
body.extend(&chunk?);
}
- serde_json::from_slice(&body).map_err(Error::Serde)
+ serde_json::from_slice(&body).map_err(Error::DeserializeError)
}
pub async fn parse_rest_response(