Skip to content

Commit

Permalink
Use #[from] attribute for new Http errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Sep 24, 2023
1 parent 2333eb9 commit 1823046
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub enum Error {
HttpError(reqwest::Error),

#[error("Invalid URL: {}", .0)]
InvalidUrl(url::ParseError),
InvalidUrl(#[from] url::ParseError),

/// The http client encountered an error.
#[error("Invalid HTTP header: {}", .0)]
InvalidHttpHeaderValue(http::header::InvalidHeaderValue),
InvalidHttpHeaderValue(#[from] http::header::InvalidHeaderValue),

/// The http client encountered an error.
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -293,12 +293,6 @@ impl std::fmt::Display for ErrorCode {
}
}

impl From<http::header::InvalidHeaderValue> for Error {
fn from(error: http::header::InvalidHeaderValue) -> Error {
Error::InvalidHttpHeaderValue(error)
}
}

#[cfg(all(
not(target_arch = "wasm32"),
any(feature = "isahc-static-curl", feature = "isahc-static-ssl")
Expand Down
10 changes: 3 additions & 7 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,9 @@ trait RequestClient<'a, B: 'a>: Sized {
Q: Serialize + 'a,
T: DeserializeOwned,
{
let mut request_client = Self::new(
add_query_parameters(url, method.query())?
.parse()
.map_err(Error::InvalidUrl)?,
)
.with_method(method.http_method())
.append_header(header::USER_AGENT, USER_AGENT_HEADER_VALUE.clone());
let mut request_client = Self::new(add_query_parameters(url, method.query())?.parse()?)
.with_method(method.http_method())
.append_header(header::USER_AGENT, USER_AGENT_HEADER_VALUE.clone());

if let Some(apikey) = apikey {
request_client = request_client
Expand Down

0 comments on commit 1823046

Please sign in to comment.