if failed to retrive content length, then print error

This commit is contained in:
Love 2023-01-19 17:57:41 +01:00
parent 44b406c4b1
commit 2fe24e04bd

View File

@ -71,7 +71,12 @@ pub async fn download_with_progress(
.send() .send()
.await .await
.or(Err("Failed to connect server".to_owned()))?; .or(Err("Failed to connect server".to_owned()))?;
let content_length = resp.content_length().unwrap(); let content_length = match resp.content_length() {
Some(k) => k,
None => {
panic!("Could not retrive content length from server. {:?}", &resp);
}
};
let pb = ProgressBar::new(content_length); let pb = ProgressBar::new(content_length);
pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})").unwrap() pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})").unwrap()