Skip to content

Commit

Permalink
Fix regression from v0.1: don't discard unsuccessful HTTP status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohikar committed Aug 26, 2022
1 parent d89de1f commit 0ba65f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byhttp"
version = "0.2.0"
version = "0.2.1"
authors = ["Lohikar <[email protected]>"]
edition = "2018"
publish = false
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ This is returned if the input to the function was invalid, or if ByHTTP failed t

- `1` - Too few arguments passed to function.
- `2` - Too many arguments passed to function.
- `100` - Unknown HTTP error.
- `101` - Connection timed out or failed to connect.
- `102` - Too many redirects.
- `200` - Error decoding or encoding JSON.
Expand Down
1 change: 0 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl ByError {
Self::TooManyArgs => 2,
Self::Ureq(ureq::Error::Transport(t)) if t.kind() == ureq::ErrorKind::Io => 101, // timeout
Self::Ureq(ureq::Error::Transport(t)) if t.kind() == ureq::ErrorKind::TooManyRedirects => 102,
Self::Ureq(ureq::Error::Status(..)) => 100,
Self::Ureq(..) => 99,
Self::Json { .. } => 200,
Self::BodyTooLarge => 201,
Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ fn send_post_internal(args: Vec<Cow<'_, str>>) -> Result<(String, u16), ByError>
_ => unreachable!()
}

let response = req.send_string(&body)?;
// Match v0.1 behavior: don't discard unsuccessful HTTP error codes.
let response = match req.send_string(&body) {
Ok(val) => val,
Err(ureq::Error::Status(_code, resp)) => resp,
Err(e) => return Err(e.into())
};
let status = response.status();
let body = response.into_string().map_err(|_| ByError::BodyTooLarge)?;

Expand All @@ -123,7 +128,12 @@ fn send_get_internal(args: Vec<Cow<'_, str>>) -> Result<(String, u16), ByError>
_ => unreachable!(),
}

let response = req.call()?;
// Match v0.1 behavior: don't discard unsuccessful HTTP error codes.
let response = match req.call() {
Ok(val) => val,
Err(ureq::Error::Status(_code, resp)) => resp,
Err(e) => return Err(e.into())
};
let status = response.status();
let body = response.into_string().map_err(|_| ByError::BodyTooLarge)?;

Expand Down

0 comments on commit 0ba65f8

Please sign in to comment.