diff --git a/CHANGELOG.md b/CHANGELOG.md index b4286c41..52a958d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Also print stack parameters when describing a demo ([#251](https://github.com/stackabletech/stackablectl/pull/251)) +### Fixed + +- Check HTTP status code when fetching resources via HTTP ([#258](https://github.com/stackabletech/stackablectl/pull/258)) + ## [0.8.0] - 2023-02-23 ### Changed diff --git a/src/helpers.rs b/src/helpers.rs index ad29abe7..7be9e81d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -40,8 +40,16 @@ pub async fn read_from_url_or_file(url_or_file: &str) -> Result } match reqwest::get(url_or_file).await { - Ok(response) => response.text().await - .map_err(|err| format!("Failed to read from the response of the file or a URL with the name \"{url_or_file}\": {err}")), + Ok(response) => { + let response_status = response.status(); + if response_status.is_success() { + response.text().await + .map_err(|err| format!("Failed to read from the response of the file or a URL with the name \"{url_or_file}\": {err}")) + } else { + Err(format!("Couldn't read from URL \"{url_or_file}\", got HTTP status code: {response_status}, expected 2xx")) + } + } + Err(err) => Err(format!( "Couldn't read a file or a URL with the name \"{url_or_file}\": {err}" )),