Merge pull request #39 from mxve/main

check http status code
This commit is contained in:
2026-03-11 14:23:35 +01:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

View File

@@ -36,6 +36,10 @@ pub async fn download_file_progress(
format!("Failed to GET from '{url}'") format!("Failed to GET from '{url}'")
})?; })?;
if !res.status().is_success() {
return Err(format!("Request failed with status: {}", res.status()));
}
let total_size = res.content_length().unwrap_or(size); let total_size = res.content_length().unwrap_or(size);
debug!("Download size: {}", misc::human_readable_bytes(total_size)); debug!("Download size: {}", misc::human_readable_bytes(total_size));
pb.set_length(total_size); pb.set_length(total_size);
@@ -93,6 +97,10 @@ pub async fn get_body(url: &str) -> Result<Vec<u8>, String> {
debug!("{} {url}", res.status()); debug!("{} {url}", res.status());
if !res.status().is_success() {
return Err(format!("Request failed with status: {}", res.status()));
}
res.bytes() res.bytes()
.await .await
.map(|b| b.to_vec()) .map(|b| b.to_vec())

View File

@@ -93,7 +93,7 @@ pub async fn run(update_only: bool, prerelease: Option<bool>) {
"alterware-launcher.exe" "alterware-launcher.exe"
}; };
http_async::download_file( if let Err(e) = http_async::download_file(
&format!( &format!(
"{}/download/{}", "{}/download/{}",
github::download_url(GH_OWNER, GH_REPO, None), github::download_url(GH_OWNER, GH_REPO, None),
@@ -102,7 +102,11 @@ pub async fn run(update_only: bool, prerelease: Option<bool>) {
&file_path, &file_path,
) )
.await .await
.unwrap(); {
error!("Self-update download failed: {e}");
crate::println_error!("Self-update failed ({e}), skipping update.");
return;
}
if !file_path.exists() { if !file_path.exists() {
crate::println_error!("Failed to download launcher update."); crate::println_error!("Failed to download launcher update.");