Skip to content

Commit

Permalink
Change error description to no explicitly refer to reqwest
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Dec 11, 2023
1 parent 900bafe commit f24b729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 8 additions & 6 deletions opensearch/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ where
}

#[derive(Debug, thiserror::Error)]
pub(crate) enum Kind {
enum Kind {
#[error("transport builder error: {0}")]
TransportBuilder(#[from] transport::BuildError),

#[error("certificate error: {0}")]
Certificate(#[from] CertificateError),

#[error("reqwest error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("http error: {0}")]
Http(#[from] reqwest::Error),

#[error("URL parse error: {0}")]
UrlParse(#[from] url::ParseError),
Expand All @@ -82,25 +82,27 @@ pub(crate) enum Kind {
AwsSigV4(#[from] crate::http::aws_auth::AwsSigV4Error),
}

use Kind::*;

impl Error {
/// The status code, if the error was generated from a response
pub fn status_code(&self) -> Option<StatusCode> {
match &self.0 {
Kind::Reqwest(err) => err.status(),
Http(err) => err.status(),
_ => None,
}
}

/// Returns true if the error is related to a timeout
pub fn is_timeout(&self) -> bool {
match &self.0 {
Kind::Reqwest(err) => err.is_timeout(),
Http(err) => err.is_timeout(),
_ => false,
}
}

/// Returns true if the error is related to serialization or deserialization
pub fn is_json(&self) -> bool {
matches!(self.0, Kind::Json(_))
matches!(self.0, Json(_))
}
}
14 changes: 6 additions & 8 deletions opensearch/src/http/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ use url::Url;
pub(crate) enum BuildError {
#[error("proxy configuration error: {0}")]
Proxy(#[source] reqwest::Error),
#[error("reqwest configuration error: {0}")]
Reqwest(#[source] reqwest::Error),
#[error("client configuration error: {0}")]
ClientBuilder(#[source] reqwest::Error),
}

/// Default address to OpenSearch running on `http://localhost:9200`
Expand Down Expand Up @@ -290,7 +290,7 @@ impl TransportBuilder {
client_builder = client_builder.proxy(proxy);
}

let client = client_builder.build().map_err(BuildError::Reqwest)?;
let client = client_builder.build().map_err(BuildError::ClientBuilder)?;
Ok(Transport {
client,
conn_pool: self.conn_pool,
Expand Down Expand Up @@ -466,11 +466,9 @@ impl Transport {
.await?;
}

let response = self.client.execute(request).await;
match response {
Ok(r) => Ok(Response::new(r, method)),
Err(e) => Err(e.into()),
}
let response = self.client.execute(request).await?;

Ok(Response::new(response, method))
}
}

Expand Down

0 comments on commit f24b729

Please sign in to comment.