Rename Error::ClientError and RefreshError::ConnectionError to HttpError.

PollError already contained an HttpError variant so this makes all
variants that contain a hyper::Error consistently named.
This commit is contained in:
Glenn Griffin
2019-11-21 12:53:02 -08:00
parent ae2258bc7a
commit fe5ea9bdb2
4 changed files with 11 additions and 25 deletions

View File

@@ -153,7 +153,7 @@ impl DeviceFlow {
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(hyper::Body::from(req))
.unwrap();
let resp = client.request(req).await.map_err(Error::ClientError)?;
let resp = client.request(req).await?;
// This return type is defined in https://tools.ietf.org/html/draft-ietf-oauth-device-flow-15#section-3.2
// The alias is present as Google use a non-standard name for verification_uri.
// According to the standard interval is optional, however, all tested implementations provide it.

View File

@@ -71,7 +71,7 @@ impl StdError for PollError {
#[derive(Debug)]
pub enum Error {
/// Indicates connection failure
ClientError(hyper::Error),
HttpError(hyper::Error),
/// The server returned an error.
NegativeServerResponse {
/// The error code
@@ -93,7 +93,7 @@ pub enum Error {
impl From<hyper::Error> for Error {
fn from(error: hyper::Error) -> Error {
Error::ClientError(error)
Error::HttpError(error)
}
}
@@ -121,7 +121,7 @@ impl From<RefreshError> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
Error::ClientError(ref err) => err.fmt(f),
Error::HttpError(ref err) => err.fmt(f),
Error::NegativeServerResponse {
ref error,
ref error_description,
@@ -148,7 +148,7 @@ impl fmt::Display for Error {
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match *self {
Error::ClientError(ref err) => Some(err),
Error::HttpError(ref err) => Some(err),
Error::LowLevelError(ref err) => Some(err),
Error::JSONError(ref err) => Some(err),
_ => None,
@@ -160,14 +160,14 @@ impl StdError for Error {
#[derive(Debug)]
pub enum RefreshError {
/// Indicates connection failure
ConnectionError(hyper::Error),
HttpError(hyper::Error),
/// The server did not answer with a new token, providing the server message
ServerError(String, Option<String>),
}
impl From<hyper::Error> for RefreshError {
fn from(value: hyper::Error) -> Self {
RefreshError::ConnectionError(value)
RefreshError::HttpError(value)
}
}

View File

@@ -185,15 +185,8 @@ impl InstalledFlow {
{
let redirect_uri = self.flow_delegate.redirect_uri();
let request = Self::request_token(app_secret, authcode, redirect_uri, server_addr);
let resp = hyper_client
.request(request)
.await
.map_err(Error::ClientError)?;
let body = resp
.into_body()
.try_concat()
.await
.map_err(Error::ClientError)?;
let resp = hyper_client.request(request).await?;
let body = resp.into_body().try_concat().await?;
#[derive(Deserialize)]
struct JSONTokenResponse {

View File

@@ -200,15 +200,8 @@ impl ServiceAccountFlow {
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(hyper::Body::from(rqbody))
.unwrap();
let response = hyper_client
.request(request)
.await
.map_err(Error::ClientError)?;
let body = response
.into_body()
.try_concat()
.await
.map_err(Error::ClientError)?;
let response = hyper_client.request(request).await?;
let body = response.into_body().try_concat().await?;
/// This is the schema of the server's response.
#[derive(Deserialize, Debug)]