From 5610dcf2d591d2b7da16b2765507fd29eb8e7643 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 10 May 2023 13:24:29 +0200 Subject: fix: Handle no internet on serverbrowser fetch (#322) Instead of panic, simply return an error --- src-tauri/src/main.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src-tauri') 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 { 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 = serde_json::from_str(&res).expect("JSON was not well-formatted"); -- cgit v1.2.3