Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 8, 2024
1 parent c021e29 commit f469be0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
9 changes: 7 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use reqwest::{
use serde::Serialize;
use serde_json::{json, Map, Value};

use crate::error::Error;
use crate::{
commons::{BindingDestinationType, UserLimitTarget, VirtualHostLimitTarget},
path,
Expand All @@ -29,7 +30,6 @@ use crate::{
},
responses::{self, BindingInfo, DefinitionSet},
};
use crate::error::Error;

type HttpClientResponse = reqwest::Response;

Expand Down Expand Up @@ -1277,7 +1277,12 @@ where
if status.is_client_error() {
match client_expect_code_error {
Some(expect) if status == expect => {}
_ => return Err(Error::ClientErrorResponse(status, response.error_for_status()?)),
_ => {
return Err(Error::ClientErrorResponse(
status,
response.error_for_status()?,
))
}
}
}

Expand Down
74 changes: 38 additions & 36 deletions src/blocking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::fmt;
use reqwest::{
blocking::Client as HttpClient,
header::{HeaderMap, HeaderValue},
StatusCode,
};
use serde::Serialize;
use serde_json::{json, Map, Value};
use backtrace::Backtrace;
use crate::error::Error;
use crate::error::Error::{
ClientErrorResponse, InvalidHeaderValue, NotFound, RequestError, ServerErrorResponse,
};
use crate::{
commons::{BindingDestinationType, UserLimitTarget, VirtualHostLimitTarget},
path,
Expand All @@ -30,7 +24,15 @@ use crate::{
},
responses::{self, BindingInfo, DefinitionSet},
};
use crate::error::Error::{ClientErrorResponse, InvalidHeaderValue, NotFound, RequestError, ServerErrorResponse};
use backtrace::Backtrace;
use reqwest::{
blocking::Client as HttpClient,
header::{HeaderMap, HeaderValue},
StatusCode,
};
use serde::Serialize;
use serde_json::{json, Map, Value};
use std::fmt;

type HttpClientResponse = reqwest::blocking::Response;
type HttpClientError = Error<HttpClientResponse, StatusCode, reqwest::Error, Backtrace>;
Expand All @@ -40,21 +42,19 @@ pub type Result<T> = std::result::Result<T, HttpClientError>;
impl From<reqwest::Error> for HttpClientError {
fn from(req_err: reqwest::Error) -> Self {
match req_err.status() {
None => {
RequestError {
error: req_err,
backtrace: Backtrace::new()
}
}
None => RequestError {
error: req_err,
backtrace: Backtrace::new(),
},
Some(status_code) => {
if status_code.is_client_error() {
return ClientErrorResponse {
status_code,
// reqwest::Error does not provide access to the associated
// response, if any
response: None,
backtrace: Backtrace::new()
}
backtrace: Backtrace::new(),
};
};

if status_code.is_server_error() {
Expand All @@ -63,13 +63,13 @@ impl From<reqwest::Error> for HttpClientError {
// reqwest::Error does not provide access to the associated
// response, if any
response: None,
backtrace: Backtrace::new()
}
backtrace: Backtrace::new(),
};
};

RequestError {
error: req_err,
backtrace: Backtrace::new()
backtrace: Backtrace::new(),
}
}
}
Expand All @@ -78,9 +78,7 @@ impl From<reqwest::Error> for HttpClientError {

impl From<reqwest::header::InvalidHeaderValue> for HttpClientError {
fn from(err: reqwest::header::InvalidHeaderValue) -> Self {
InvalidHeaderValue {
error: err
}
InvalidHeaderValue { error: err }
}
}

Expand Down Expand Up @@ -977,7 +975,7 @@ where
let failure_details = response.json()?;
Err(Error::HealthCheckFailed {
status_code,
details: failure_details
details: failure_details,
})
}

Expand Down Expand Up @@ -1048,7 +1046,7 @@ where
let failure_details = responses::HealthCheckFailureDetails::AlarmCheck(body);
Err(Error::HealthCheckFailed {
details: failure_details,
status_code
status_code,
})
}

Expand Down Expand Up @@ -1195,22 +1193,26 @@ where
if status.is_client_error() {
match client_code_to_accept_or_ignore {
Some(expect) if status == expect => {}
_ => return Err(ClientErrorResponse {
response: Some(response),
status_code: status,
backtrace: Backtrace::new()
}),
_ => {
return Err(ClientErrorResponse {
response: Some(response),
status_code: status,
backtrace: Backtrace::new(),
})
}
}
}

if status.is_server_error() {
match server_code_to_accept_or_ignore {
Some(expect) if status == expect => {}
_ => return Err(ServerErrorResponse {
response: Some(response),
status_code: status,
backtrace: Backtrace::new()
}),
_ => {
return Err(ServerErrorResponse {
response: Some(response),
status_code: status,
backtrace: Backtrace::new(),
})
}
}
}

Expand Down
19 changes: 7 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use reqwest::{header::InvalidHeaderValue};
use thiserror::Error;
use crate::responses;
use reqwest::header::InvalidHeaderValue;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error<R, S, E, BT> {
Expand All @@ -32,21 +32,16 @@ pub enum Error<R, S, E, BT> {
#[error("Health check failed")]
HealthCheckFailed {
details: responses::HealthCheckFailureDetails,
status_code: S
status_code: S,
},
#[error("Could not find the requested resource")]
NotFound,
#[error("Cannot delete a binding: multiple matching bindings were found, provide additional properties")]
MultipleMatchingBindings,
#[error("could not convert provided value into an HTTP header value")]
InvalidHeaderValue {
error: InvalidHeaderValue
},
InvalidHeaderValue { error: InvalidHeaderValue },
#[error("encountered an error when performing an HTTP request")]
RequestError {
error: E,
backtrace: BT,
},
RequestError { error: E, backtrace: BT },
#[error("an unspecified error")]
Other
}
Other,
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub mod requests;
/// API response types
pub mod responses;

#[cfg(any(feature = "async", feature = "blocking"))]
mod utils;
/// Error
#[cfg(any(feature = "async", feature = "blocking"))]
pub mod error;
#[cfg(any(feature = "async", feature = "blocking"))]
mod utils;

0 comments on commit f469be0

Please sign in to comment.