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

Commit ab03b8e

Browse files
committed
Fix/check http status (#258)
## Description *Please add a description here. This will become the commit message of the merge request later.*
1 parent 534b1a3 commit ab03b8e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Also print stack parameters when describing a demo ([#251](https://github.com/stackabletech/stackablectl/pull/251))
88

9+
### Fixed
10+
11+
- Check HTTP status code when fetching resources via HTTP ([#258](https://github.com/stackabletech/stackablectl/pull/258))
12+
913
## [0.8.0] - 2023-02-23
1014

1115
### Changed

src/helpers.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ pub async fn read_from_url_or_file(url_or_file: &str) -> Result<String, String>
4040
}
4141

4242
match reqwest::get(url_or_file).await {
43-
Ok(response) => response.text().await
44-
.map_err(|err| format!("Failed to read from the response of the file or a URL with the name \"{url_or_file}\": {err}")),
43+
Ok(response) => {
44+
let response_status = response.status();
45+
if response_status.is_success() {
46+
response.text().await
47+
.map_err(|err| format!("Failed to read from the response of the file or a URL with the name \"{url_or_file}\": {err}"))
48+
} else {
49+
Err(format!("Couldn't read from URL \"{url_or_file}\", got HTTP status code: {response_status}, expected 2xx"))
50+
}
51+
}
52+
4553
Err(err) => Err(format!(
4654
"Couldn't read a file or a URL with the name \"{url_or_file}\": {err}"
4755
)),

0 commit comments

Comments
 (0)