aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-05-10 13:24:29 +0200
committerGitHub <noreply@github.com>2023-05-10 13:24:29 +0200
commit5610dcf2d591d2b7da16b2765507fd29eb8e7643 (patch)
tree3208f5288bdffdca26dc4a8e12f9fe880281f5ee /src-tauri/src
parentcd07d7d48b2b3d98c3d14967c3eea52aaa8f3a11 (diff)
downloadFlightCore-5610dcf2d591d2b7da16b2765507fd29eb8e7643.tar.gz
FlightCore-5610dcf2d591d2b7da16b2765507fd29eb8e7643.zip
fix: Handle no internet on serverbrowser fetch (#322)
Instead of panic, simply return an error
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/main.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index b6c923e3..95914898 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -427,20 +427,28 @@ async fn clean_up_download_folder_caller(
}
}
-/// Gets server and playercount from master server API
-#[tauri::command]
-async fn get_server_player_count() -> Result<(i32, usize), String> {
+/// Fetches `/client/servers` endpoint from master server
+async fn fetch_server_list() -> Result<String, anyhow::Error> {
let url = format!("{MASTER_SERVER_URL}{SERVER_BROWSER_ENDPOINT}");
let client = reqwest::Client::new();
let res = client
.get(url)
.header(reqwest::header::USER_AGENT, APP_USER_AGENT)
.send()
- .await
- .unwrap()
+ .await?
.text()
- .await
- .unwrap();
+ .await?;
+
+ Ok(res)
+}
+
+/// Gets server and playercount from master server API
+#[tauri::command]
+async fn get_server_player_count() -> Result<(i32, usize), String> {
+ let res = match fetch_server_list().await {
+ Ok(res) => res,
+ Err(err) => return Err(err.to_string()),
+ };
let ns_servers: Vec<NorthstarServer> =
serde_json::from_str(&res).expect("JSON was not well-formatted");