diff --git a/CHANGELOG.md b/CHANGELOG.md index a77f1e9..c36d2ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed +- Return an error if GET request fails (#471) ### Changed diff --git a/src/error.rs b/src/error.rs index e3920b9..ed7ba92 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,6 +14,10 @@ pub enum Error { #[error("Failed to query GitHub API: Invalid Github token")] GithubTokenInvalid, + #[diagnostic(code(espup::toolchain::http_error))] + #[error("HTTP GET Error: {0}")] + HttpError(String), + #[diagnostic(code(espup::toolchain::rust::install_riscv_target))] #[error("Failed to Install RISC-V targets for '{0}' toolchain")] InstallRiscvTarget(String), diff --git a/src/toolchain/mod.rs b/src/toolchain/mod.rs index 01f030e..b1abaf6 100644 --- a/src/toolchain/mod.rs +++ b/src/toolchain/mod.rs @@ -120,7 +120,11 @@ pub async fn download_file( let resp = { let client = build_proxy_async_client()?; - client.get(&url).send().await? + let resp = client.get(&url).send().await?; + if !resp.status().is_success() { + return Err(Error::HttpError(resp.status().to_string())); + } + resp }; let bytes = { let len = resp.content_length();