Skip to content

Commit 1f13dbf

Browse files
Adopt HTTP API client 0.10.0 to produce more detailed errors
1 parent 9faf269 commit 1f13dbf

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
#![allow(clippy::result_large_err)]
15+
1416
use clap::ArgMatches;
1517
use rabbitmq_http_client::commons;
1618
use rabbitmq_http_client::commons::ExchangeType;

src/errors.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
use rabbitmq_http_client::error::Error as ApiClientError;
1616
use rabbitmq_http_client::{blocking_api::HttpClientError, responses::HealthCheckFailureDetails};
17-
use reqwest::blocking::Response;
18-
use reqwest::{header::InvalidHeaderValue, StatusCode};
17+
use reqwest::{
18+
header::{HeaderMap, InvalidHeaderValue},
19+
StatusCode,
20+
};
21+
use url::Url;
1922

2023
#[derive(thiserror::Error, Debug)]
2124
pub enum CommandRunError {
@@ -24,12 +27,16 @@ pub enum CommandRunError {
2427
#[error("API responded with a client error: status code of {status_code}")]
2528
ClientError {
2629
status_code: StatusCode,
27-
response: Option<Response>,
30+
url: Option<Url>,
31+
body: Option<String>,
32+
headers: Option<HeaderMap>,
2833
},
2934
#[error("API responded with a client error: status code of {status_code}")]
3035
ServerError {
3136
status_code: StatusCode,
32-
response: Option<Response>,
37+
url: Option<Url>,
38+
body: Option<String>,
39+
headers: Option<HeaderMap>,
3340
},
3441
#[error("Health check failed")]
3542
HealthCheckFailed {
@@ -52,18 +59,18 @@ pub enum CommandRunError {
5259
impl From<HttpClientError> for CommandRunError {
5360
fn from(value: HttpClientError) -> Self {
5461
match value {
55-
ApiClientError::ClientErrorResponse { status_code, response, .. } => {
56-
Self::ClientError { status_code, response }
62+
ApiClientError::ClientErrorResponse { status_code, url, body, headers, .. } => {
63+
Self::ClientError { status_code, url, body, headers }
5764
},
58-
ApiClientError::ServerErrorResponse { status_code, response, .. } => {
59-
Self::ServerError { status_code, response }
65+
ApiClientError::ServerErrorResponse { status_code, url, body, headers, .. } => {
66+
Self::ServerError { status_code, url, body, headers }
6067
},
6168
ApiClientError::HealthCheckFailed { path, details, status_code } => {
6269
Self::HealthCheckFailed { health_check_path: path, details, status_code }
6370
},
6471
ApiClientError::NotFound => Self::NotFound,
6572
ApiClientError::MultipleMatchingBindings => Self::ConflictingOptions {
66-
message: "multiple bindings match, cannot determing which binding to delete without explicitly provided binding properties".to_owned()
73+
message: "multiple bindings match, cannot determine which binding to delete without explicitly provided binding properties".to_owned()
6774
},
6875
ApiClientError::InvalidHeaderValue { error } => {
6976
Self::InvalidHeaderValue { error }

src/output.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ impl ResultHandler {
147147
Err(error) => match error {
148148
ClientError::ClientErrorResponse {
149149
status_code: http_code,
150-
response: _,
151-
backtrace: _,
150+
..
152151
} if http_code == StatusCode::NOT_FOUND => {
153152
if self.idempotently {
154153
self.exit_code = Some(ExitCode::Ok)

src/tables.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
use rabbitmq_http_client::blocking_api::{HttpClientError, HttpClientResponse};
14+
use rabbitmq_http_client::blocking_api::HttpClientError;
1515
use rabbitmq_http_client::responses::{HealthCheckFailureDetails, Overview};
1616
use reqwest::StatusCode;
1717
use tabled::settings::Panel;
1818
use tabled::{Table, Tabled};
19+
use url::Url;
1920

2021
#[derive(Tabled)]
2122
struct OverviewRow<'a> {
@@ -102,14 +103,16 @@ pub fn failure_details(error: &HttpClientError) -> Table {
102103
match error {
103104
HttpClientError::ClientErrorResponse {
104105
status_code,
105-
response,
106-
backtrace: _,
107-
} => generic_failed_request_details(status_code, response),
106+
url,
107+
body,
108+
..
109+
} => generic_failed_request_details(status_code, url, body),
108110
HttpClientError::ServerErrorResponse {
109111
status_code,
110-
response,
111-
backtrace: _,
112-
} => generic_failed_request_details(status_code, response),
112+
url,
113+
body,
114+
..
115+
} => generic_failed_request_details(status_code, url, body),
113116
HttpClientError::HealthCheckFailed {
114117
status_code,
115118
path,
@@ -240,10 +243,14 @@ pub fn failure_details(error: &HttpClientError) -> Table {
240243

241244
fn generic_failed_request_details(
242245
status_code: &StatusCode,
243-
response: &Option<HttpClientResponse>,
246+
url: &Option<Url>,
247+
body: &Option<String>,
244248
) -> Table {
245249
let status_code_s = status_code.to_string();
246-
let mut data = vec![
250+
let url_s = url.clone().unwrap().to_string();
251+
let body_s = body.clone().unwrap_or("N/A".to_string());
252+
253+
let data = vec![
247254
RowOfTwoStrings {
248255
key: "result",
249256
value: "request failed",
@@ -252,16 +259,15 @@ fn generic_failed_request_details(
252259
key: "status_code",
253260
value: status_code_s.as_str(),
254261
},
262+
RowOfTwoStrings {
263+
key: "url",
264+
value: url_s.as_str(),
265+
},
266+
RowOfTwoStrings {
267+
key: "body",
268+
value: body_s.as_str(),
269+
},
255270
];
256-
match response {
257-
None => (),
258-
Some(ref val) => {
259-
data.push(RowOfTwoStrings {
260-
key: "request URL",
261-
value: val.url().as_str(),
262-
});
263-
}
264-
}
265271

266272
let tb = Table::builder(data);
267273
tb.build()

0 commit comments

Comments
 (0)