Skip to content

Commit 831d88f

Browse files
committed
Fix some error handling
1 parent 12a48ad commit 831d88f

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/check.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ pub async fn check_status(state: super::AppState, client: &reqwest::Client) {
6464
);
6565

6666
println!("Changing service state");
67-
state
67+
match state
6868
.consul
6969
.register_service(is_active_host, is_eligible_host)
7070
.await
71-
.expect("failed to change service state");
71+
{
72+
Result::Ok(r) => println!("Success!"),
73+
_ => println!("Failed"),
74+
}
7275
}
7376
}
7477

@@ -92,16 +95,14 @@ pub async fn is_active_host(state: &super::AppState, client: &reqwest::Client) -
9295
let external_url = &state.app_config.external_url;
9396
let hostname = &state.app_config.hostname;
9497

95-
let external_host_res = client
96-
.get(format!("{external_url}/host"))
97-
.send()
98-
.await
99-
.expect("failed to query external_url")
100-
.text()
101-
.await
102-
.expect("failed to get host from external_url");
98+
let external_host_res = match client.get(format!("{external_url}/host")).send().await {
99+
Result::Ok(r) => Some(r).unwrap(),
100+
_ => return false,
101+
};
102+
103+
let external_host_hostname = external_host_res.text().await.unwrap_or("".into());
103104

104-
let external_host = external_host_res.trim();
105+
let external_host = external_host_hostname.trim();
105106

106107
return external_host == hostname;
107108
}

src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ async fn main() {
3939

4040
let consul = Consul::new(consul_config, app_config.clone());
4141

42-
let cluster_leader = consul.status_leader().await.unwrap();
43-
44-
println!("Cluster Leader: {cluster_leader}");
45-
4642
let _ = consul.register_service(false, false).await;
4743

4844
let state = AppState {

0 commit comments

Comments
 (0)