Skip to content

Commit

Permalink
Return error if GET request fails (#471)
Browse files Browse the repository at this point in the history
* fix: Return error if get request fails

* docs: Update changelog
  • Loading branch information
SergioGasquez authored Jan 28, 2025
1 parent 54b453b commit 6251fd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6251fd2

Please sign in to comment.