aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-27 09:39:14 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-27 09:39:14 -0600
commit1590133d7e8d1f2cc437b683ebeed2f84ff215f7 (patch)
tree99ba09b7a3bdb41dee7e3b1ef2382267a7293a93 /src
parent434d285b36cce9d29fd6a8b997469c7a929b96bc (diff)
downloadwebget-1590133d7e8d1f2cc437b683ebeed2f84ff215f7.tar.gz
webget-1590133d7e8d1f2cc437b683ebeed2f84ff215f7.zip
do not panic in download
Diffstat (limited to 'src')
-rw-r--r--src/download.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/download.rs b/src/download.rs
index 7cf9694..80a159b 100644
--- a/src/download.rs
+++ b/src/download.rs
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
-use anyhow::{Error, Context};
+use anyhow::{bail, Error, Context};
use fehler::throws;
use hyper::Uri;
use hyper::body::HttpBody;
@@ -36,7 +36,7 @@ pub(crate) async fn download(url: Uri, args: &Args) {
response = client.get(location).await?;
}
if !response.status().is_success() {
- panic!("non-success response code {} in URL {}", response.status(), url);
+ bail!("non-success response code {} in URL {}", response.status(), url);
}
let output_file_path = if let Some(path) = output_file_path {
@@ -51,7 +51,7 @@ pub(crate) async fn download(url: Uri, args: &Args) {
PathBuf::from(format!("index{}", extension))
};
- let mut output_file = fs::File::create(output_file_path).await.expect("couldn't open output file!");
+ let mut output_file = fs::File::create(output_file_path).await?;
while let Some(data) = response.body_mut().data().await {
output_file.write_all(&data?).await?;