Skip to content

Commit 06a4392

Browse files
Refactoring
* Optimize imports while avoiding naming conflicts * Minor simplification to a return value
1 parent 34a420d commit 06a4392

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

src/errors.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use rabbitmq_http_client::error::{ConversionError, Error as ApiClientError};
15+
use rabbitmq_http_client::error::{ConversionError, Error as ApiClientError, ErrorDetails};
1616
use rabbitmq_http_client::{blocking_api::HttpClientError, responses::HealthCheckFailureDetails};
17-
use reqwest::{
18-
StatusCode,
19-
header::{HeaderMap, InvalidHeaderValue},
20-
};
17+
use reqwest::StatusCode;
18+
use reqwest::header::{HeaderMap, InvalidHeaderValue};
2119
use std::io;
2220
use url::Url;
2321

@@ -65,15 +63,15 @@ pub enum CommandRunError {
6563
status_code: StatusCode,
6664
url: Option<Url>,
6765
body: Option<String>,
68-
error_details: Option<rabbitmq_http_client::error::ErrorDetails>,
66+
error_details: Option<ErrorDetails>,
6967
headers: Option<HeaderMap>,
7068
},
7169
#[error("{}", format_server_error(.status_code, .error_details))]
7270
ServerError {
7371
status_code: StatusCode,
7472
url: Option<Url>,
7573
body: Option<String>,
76-
error_details: Option<rabbitmq_http_client::error::ErrorDetails>,
74+
error_details: Option<ErrorDetails>,
7775
headers: Option<HeaderMap>,
7876
},
7977
#[error("Health check failed")]
@@ -114,36 +112,32 @@ impl From<io::Error> for CommandRunError {
114112

115113
impl From<HttpClientError> for CommandRunError {
116114
fn from(value: HttpClientError) -> Self {
117-
use ApiClientError::*;
118115
match value {
119-
UnsupportedArgumentValue { property } => Self::UnsupportedArgumentValue { property },
120-
ClientErrorResponse { status_code, url, body, error_details, headers, .. } => {
116+
ApiClientError::UnsupportedArgumentValue { property } => Self::UnsupportedArgumentValue { property },
117+
ApiClientError::ClientErrorResponse { status_code, url, body, error_details, headers, .. } => {
121118
Self::ClientError { status_code, url, body, error_details, headers }
122119
}
123-
ServerErrorResponse { status_code, url, body, error_details, headers, .. } => {
120+
ApiClientError::ServerErrorResponse { status_code, url, body, error_details, headers, .. } => {
124121
Self::ServerError { status_code, url, body, error_details, headers }
125122
}
126-
HealthCheckFailed { path, details, status_code } => {
123+
ApiClientError::HealthCheckFailed { path, details, status_code } => {
127124
Self::HealthCheckFailed { health_check_path: path, details, status_code }
128125
}
129-
NotFound => Self::NotFound,
130-
MultipleMatchingBindings => Self::ConflictingOptions {
126+
ApiClientError::NotFound => Self::NotFound,
127+
ApiClientError::MultipleMatchingBindings => Self::ConflictingOptions {
131128
message: "multiple bindings match, cannot determine which binding to delete without explicitly provided binding properties".to_owned()
132129
},
133-
InvalidHeaderValue { error } => Self::InvalidHeaderValue { error },
134-
RequestError { error, .. } => Self::RequestError { error },
135-
Other => Self::Other,
136-
MissingProperty { argument } => Self::MissingArgumentValue { property: argument },
137-
IncompatibleBody { error, .. } => Self::IncompatibleBody { error },
138-
ParsingError { message } => Self::FailureDuringExecution { message },
130+
ApiClientError::InvalidHeaderValue { error } => Self::InvalidHeaderValue { error },
131+
ApiClientError::RequestError { error, .. } => Self::RequestError { error },
132+
ApiClientError::Other => Self::Other,
133+
ApiClientError::MissingProperty { argument } => Self::MissingArgumentValue { property: argument },
134+
ApiClientError::IncompatibleBody { error, .. } => Self::IncompatibleBody { error },
135+
ApiClientError::ParsingError { message } => Self::FailureDuringExecution { message },
139136
}
140137
}
141138
}
142139

143-
fn format_client_error(
144-
status_code: &StatusCode,
145-
error_details: &Option<rabbitmq_http_client::error::ErrorDetails>,
146-
) -> String {
140+
fn format_client_error(status_code: &StatusCode, error_details: &Option<ErrorDetails>) -> String {
147141
if let Some(details) = error_details
148142
&& let Some(reason) = details.reason()
149143
{
@@ -155,10 +149,7 @@ fn format_client_error(
155149
)
156150
}
157151

158-
fn format_server_error(
159-
status_code: &StatusCode,
160-
error_details: &Option<rabbitmq_http_client::error::ErrorDetails>,
161-
) -> String {
152+
fn format_server_error(status_code: &StatusCode, error_details: &Option<ErrorDetails>) -> String {
162153
if let Some(details) = error_details
163154
&& let Some(reason) = details.reason()
164155
{

src/tables.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
use rabbitmq_http_client::blocking_api::HttpClientError;
15+
use rabbitmq_http_client::error::ErrorDetails;
1516
use rabbitmq_http_client::formatting::*;
1617
use rabbitmq_http_client::password_hashing::HashingError;
1718
use rabbitmq_http_client::responses::{
@@ -498,7 +499,7 @@ fn generic_failed_request_details(
498499
status_code: &StatusCode,
499500
url: &Option<Url>,
500501
body: &Option<String>,
501-
error_details: &Option<rabbitmq_http_client::error::ErrorDetails>,
502+
error_details: &Option<ErrorDetails>,
502503
) -> Table {
503504
let status_code_s = status_code.to_string();
504505
let url_s = url.clone().unwrap().to_string();

0 commit comments

Comments
 (0)