Return error if GET request fails (#471)

* fix: Return error if get request fails

* docs: Update changelog
This commit is contained in:
Sergio Gasquez Arcos 2025-01-28 09:51:27 +01:00 committed by GitHub
parent 54b453b172
commit 6251fd2b7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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),

View File

@ -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();