mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 15:27:48 +00:00
handle some networking errors
assume we are up to date if we can't fetch latest version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use semver::Version;
|
||||
|
||||
pub async fn latest_tag(owner: &str, repo: &str) -> String {
|
||||
pub async fn latest_tag(owner: &str, repo: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let github_body = crate::http_async::get_body_string(
|
||||
format!(
|
||||
"https://api.github.com/repos/{}/{}/releases/latest",
|
||||
@@ -8,23 +8,32 @@ pub async fn latest_tag(owner: &str, repo: &str) -> String {
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await?;
|
||||
|
||||
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
|
||||
let github_json: serde_json::Value = serde_json::from_str(&github_body)?;
|
||||
|
||||
if let Some(tag_name) = github_json.get("tag_name") {
|
||||
if let Some(tag_name_str) = tag_name.as_str() {
|
||||
return tag_name_str.to_string().replace('"', "");
|
||||
return Ok(tag_name_str.to_string().replace('"', ""));
|
||||
}
|
||||
}
|
||||
|
||||
"0.0.0".to_string()
|
||||
Ok("0.0.0".to_string())
|
||||
}
|
||||
|
||||
pub async fn latest_version(owner: &str, repo: &str) -> Version {
|
||||
let tag = latest_tag(owner, repo).await.replace('v', "");
|
||||
Version::parse(&tag).unwrap()
|
||||
match latest_tag(owner, repo).await {
|
||||
Ok(tag) => {
|
||||
let cleaned_tag = tag.replace('v', "");
|
||||
Version::parse(&cleaned_tag).unwrap_or_else(|_| Version::new(0, 0, 0))
|
||||
}
|
||||
Err(_) => {
|
||||
crate::println_error!(
|
||||
"Failed to get latest version for {owner}/{repo}, assuming we are up to date."
|
||||
);
|
||||
Version::new(0, 0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn latest_release_url(owner: &str, repo: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user