From 5637f62a8bd20a30ed2414615ab28e1ae2337132 Mon Sep 17 00:00:00 2001 From: loveb Date: Thu, 19 Jan 2023 17:57:41 +0100 Subject: [PATCH] if failed to retrive content length, then print error --- src/downloader.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/downloader.rs b/src/downloader.rs index e5f2d76..8bfd56f 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -71,7 +71,12 @@ pub async fn download_with_progress( .send() .await .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); pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})").unwrap()