From 720cea0800ca1dc424f56df74e95bb66014d633f Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Tue, 14 May 2024 09:21:41 -0400 Subject: [PATCH] Properly handle failed downloads --- docs/changelog.md | 4 ++++ src/network.rs | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 103569c..2fb9f8d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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:*** diff --git a/src/network.rs b/src/network.rs index 93b9292..9ec3e30 100644 --- a/src/network.rs +++ b/src/network.rs @@ -1,6 +1,6 @@ use std::io::Write; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use crate::terminal; @@ -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) + } }