Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

[Merged by Bors] - Fix/check http status #258

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ pub async fn read_from_url_or_file(url_or_file: &str) -> Result<String, String>
}

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}"
)),
Expand Down