aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-05-15 15:00:55 +0200
committerGitHub <noreply@github.com>2023-05-15 15:00:55 +0200
commit002d967aac31a7c7b883cc6f2003e2db7afa6247 (patch)
tree61adaea01c5a9517db61ed13c0984b28436fdf73 /src-tauri/src
parent11beab3bc57412d5be72c5dec2948bad3e29ac44 (diff)
downloadFlightCore-002d967aac31a7c7b883cc6f2003e2db7afa6247.tar.gz
FlightCore-002d967aac31a7c7b883cc6f2003e2db7afa6247.zip
fix: Do not crash if not able to connect to TS (#346)
* fix: Do not crash if not able to connect to TS Removes a bunch of `unwrap`s that would cause the thread to crash if connection to Thunderstore failed. * feat: Show failure notification in frontend
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/thunderstore/mod.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src-tauri/src/thunderstore/mod.rs b/src-tauri/src/thunderstore/mod.rs
index bd4204b4..fc2acb02 100644
--- a/src-tauri/src/thunderstore/mod.rs
+++ b/src-tauri/src/thunderstore/mod.rs
@@ -40,24 +40,34 @@ pub struct ThunderstoreModVersion {
pub file_size: i64,
}
-/// Queries Thunderstore packages API
-#[tauri::command]
-pub async fn query_thunderstore_packages_api() -> Result<Vec<ThunderstoreMod>, String> {
+/// Performs actual fetch from Thunderstore and returns response
+async fn fetch_thunderstore_packages() -> Result<String, reqwest::Error> {
log::info!("Fetching Thunderstore API");
// Fetches
let url = "https://northstar.thunderstore.io/api/v1/package/";
let client = reqwest::Client::new();
- let res = client
+ client
.get(url)
.header(reqwest::header::USER_AGENT, APP_USER_AGENT)
.send()
- .await
- .unwrap()
+ .await?
.text()
.await
- .unwrap();
+}
+
+/// Queries Thunderstore packages API
+#[tauri::command]
+pub async fn query_thunderstore_packages_api() -> Result<Vec<ThunderstoreMod>, String> {
+ let res = match fetch_thunderstore_packages().await {
+ Ok(res) => res,
+ Err(err) => {
+ let warn_response = format!("Couldn't fetch from Thunderstore: {err}");
+ log::warn!("{warn_response}");
+ return Err(warn_response);
+ }
+ };
// Parse response
let parsed_json: Vec<ThunderstoreMod> = match serde_json::from_str(&res) {