aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/github/release_notes.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-06-02 15:09:01 +0200
committerGitHub <noreply@github.com>2023-06-02 15:09:01 +0200
commita21082ce8da5b020d97d5f94c24f1448c96f3cb2 (patch)
treecc2d3f21b91b85a80a8b916625f85b762a2c2c97 /src-tauri/src/github/release_notes.rs
parent9652259ba345056186a6e4d0112ee7c48f24e479 (diff)
downloadFlightCore-a21082ce8da5b020d97d5f94c24f1448c96f3cb2.tar.gz
FlightCore-a21082ce8da5b020d97d5f94c24f1448c96f3cb2.zip
fix: Remove some unwraps for fetching GitHub API (#375)
Remove some unwraps for fetching GitHub API to prevent thread from panicking on no internet
Diffstat (limited to 'src-tauri/src/github/release_notes.rs')
-rw-r--r--src-tauri/src/github/release_notes.rs18
1 files changed, 11 insertions, 7 deletions
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<String, String> {
+pub async fn fetch_github_releases_api(url: &str) -> Result<String, anyhow::Error> {
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<String, String> {
.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<FlightCoreVersion, String
// Get newest version number from GitHub API
log::info!("Checking GitHub API");
let url = "https://api.github.com/repos/R2NorthstarTools/FlightCore/releases/latest";
- 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 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<bool, String> {
#[tauri::command]
pub async fn get_northstar_release_notes() -> Result<Vec<ReleaseInfo>, 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<ReleaseInfo> = match serde_json::from_str(&res) {
Ok(res) => res,