From a21082ce8da5b020d97d5f94c24f1448c96f3cb2 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:09:01 +0200 Subject: fix: Remove some unwraps for fetching GitHub API (#375) Remove some unwraps for fetching GitHub API to prevent thread from panicking on no internet --- src-tauri/src/github/pull_requests.rs | 2 +- src-tauri/src/github/release_notes.rs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index b30fd272..44b41638 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -74,7 +74,7 @@ pub async fn get_pull_requests(url: String) -> Result result, - Err(err) => return Err(err), + Err(err) => return Err(format!("Failed fetching GitHub API {err}")), }; let pulls_response: Vec = diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs index ea432af0..6db5b617 100644 --- a/src-tauri/src/github/release_notes.rs +++ b/src-tauri/src/github/release_notes.rs @@ -19,7 +19,7 @@ pub struct FlightCoreVersion { } // Fetches repo release API and returns response as string -pub async fn fetch_github_releases_api(url: &str) -> Result { +pub async fn fetch_github_releases_api(url: &str) -> Result { log::info!("Fetching releases notes from GitHub API"); let client = reqwest::Client::new(); @@ -27,11 +27,9 @@ pub async fn fetch_github_releases_api(url: &str) -> Result { .get(url) .header(reqwest::header::USER_AGENT, APP_USER_AGENT) .send() - .await - .unwrap() + .await? .text() - .await - .unwrap(); + .await?; Ok(res) } @@ -42,7 +40,10 @@ pub async fn get_newest_flightcore_version() -> Result res, + Err(err) => return Err(format!("Failed getting newest FlightCore version: {err}")), + }; let flightcore_version: FlightCoreVersion = serde_json::from_str(&res).expect("JSON was not well-formatted"); @@ -95,7 +96,10 @@ pub async fn check_is_flightcore_outdated() -> Result { #[tauri::command] pub async fn get_northstar_release_notes() -> Result, String> { let url = "https://api.github.com/repos/R2Northstar/Northstar/releases"; - let res = fetch_github_releases_api(url).await?; + let res = match fetch_github_releases_api(url).await { + Ok(res) => res, + Err(err) => return Err(format!("Failed getting Northstar release notes: {err}")), + }; let release_info_vector: Vec = match serde_json::from_str(&res) { Ok(res) => res, -- cgit v1.2.3