Skip to content

Commit

Permalink
Properly handle failed downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed May 14, 2024
1 parent 90091ba commit 720cea0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

***Fixed:***

- Properly handle failed downloads

## 0.20.0 - 2024-05-13

***Added:***
Expand Down
8 changes: 6 additions & 2 deletions src/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::Write;

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};

use crate::terminal;

Expand All @@ -15,5 +15,9 @@ pub fn download(url: &String, writer: impl Write, description: &str) -> Result<(
response.copy_to(&mut pb.wrap_write(writer))?;
pb.finish_and_clear();

Ok(())
if response.status().is_success() {
Ok(())
} else {
bail!("download failed: {}, {}", response.status(), url)
}
}

0 comments on commit 720cea0

Please sign in to comment.