Unverified Commit 6b38bf71 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Concrete body in SdkResult/SdkError (#247)

* Refactor out generic `B` parameter from SdkResult / SdkError

* Switch to from_static

* Add docs, fix old broken docs

* Remove unused From<Bytes> bound

* Rustfmt run
parent d75b7605
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -48,11 +48,11 @@ impl Default for AwsErrorRetryPolicy {
    }
}

impl<T, E, B> ClassifyResponse<T, SdkError<E, B>> for AwsErrorRetryPolicy
impl<T, E> ClassifyResponse<T, SdkError<E>> for AwsErrorRetryPolicy
where
    E: ProvideErrorKind,
{
    fn classify(&self, err: Result<&T, &SdkError<E, B>>) -> RetryKind {
    fn classify(&self, err: Result<&T, &SdkError<E>>) -> RetryKind {
        let (err, response) = match err {
            Ok(_) => return RetryKind::NotRetryable,
            Err(SdkError::ServiceError { err, raw }) => (err, raw),
@@ -88,6 +88,7 @@ where
#[cfg(test)]
mod test {
    use crate::AwsErrorRetryPolicy;
    use smithy_http::middleware::ResponseBody;
    use smithy_http::result::{SdkError, SdkSuccess};
    use smithy_http::retry::ClassifyResponse;
    use smithy_types::retry::{ErrorKind, ProvideErrorKind, RetryKind};
@@ -119,8 +120,14 @@ mod test {
        }
    }

    fn make_err<E, B>(err: E, raw: http::Response<B>) -> Result<SdkSuccess<(), B>, SdkError<E, B>> {
        Err(SdkError::ServiceError { err, raw })
    fn make_err<E>(
        err: E,
        raw: http::Response<&'static str>,
    ) -> Result<SdkSuccess<()>, SdkError<E>> {
        Err(SdkError::ServiceError {
            err,
            raw: raw.map(|b| ResponseBody::from_static(b)),
        })
    }

    #[test]
+3 −1
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ impl Standard {
    /// An https connection
    pub fn https() -> Self {
        let https = HttpsConnector::new();
        Self(Connector::Https(hyper::Client::builder().build::<_, SdkBody>(https)))
        Self(Connector::Https(
            hyper::Client::builder().build::<_, SdkBody>(https),
        ))
    }

    /// A connection based on the provided `impl HttpService`
+2 −4
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use aws_sig_auth::signer::SigV4Signer;
use smithy_http::body::SdkBody;
use smithy_http::operation::Operation;
use smithy_http::response::ParseHttpResponse;
pub use smithy_http::result::{SdkError, SdkSuccess};
use smithy_http::retry::ClassifyResponse;
use smithy_http_tower::dispatch::DispatchLayer;
use smithy_http_tower::map_request::MapRequestLayer;
@@ -27,9 +28,6 @@ use tower::{Service, ServiceBuilder, ServiceExt};
type BoxError = Box<dyn Error + Send + Sync>;
pub type StandardClient = Client<conn::Standard>;

pub type SdkError<E> = smithy_http::result::SdkError<E, hyper::Body>;
pub type SdkSuccess<T> = smithy_http::result::SdkSuccess<T, hyper::Body>;

/// AWS Service Client
///
/// Hyper-based AWS Service Client. Most customers will want to construct a client with
@@ -138,8 +136,8 @@ where

#[cfg(test)]
mod tests {
    use crate::{Client, conn};
    use crate::test_connection::TestConnection;
    use crate::{conn, Client};

    #[test]
    fn construct_default_client() {
+12 −8
Original line number Diff line number Diff line
@@ -5,13 +5,13 @@

use http::header::{HeaderName, CONTENT_TYPE};
use http::Request;
use protocol_test_helpers::{assert_ok, validate_body, MediaType};
use smithy_http::body::SdkBody;
use std::future::Ready;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use tower::BoxError;
use protocol_test_helpers::{validate_body, MediaType, assert_ok};

type ConnectVec<B> = Vec<(http::Request<SdkBody>, http::Response<B>)>;

@@ -34,14 +34,18 @@ impl ValidateRequest {
        }
        let actual_str = std::str::from_utf8(actual.body().bytes().unwrap_or(&[]));
        let expected_str = std::str::from_utf8(expected.body().bytes().unwrap_or(&[]));
        let media_type = if actual.headers().get(CONTENT_TYPE).map(|v| v.to_str().unwrap().contains("json")).unwrap_or(false) {
        let media_type = if actual
            .headers()
            .get(CONTENT_TYPE)
            .map(|v| v.to_str().unwrap().contains("json"))
            .unwrap_or(false)
        {
            MediaType::Json
        } else {
            MediaType::Other("unknown".to_string())
        };
        match (actual_str, expected_str) {
            (Ok(actual), Ok(expected)) =>
                assert_ok(validate_body(actual, expected, media_type)),
            (Ok(actual), Ok(expected)) => assert_ok(validate_body(actual, expected, media_type)),
            _ => assert_eq!(actual.body().bytes(), expected.body().bytes()),
        };
        assert_eq!(actual.uri(), expected.uri());
+2 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use aws_endpoint::{set_endpoint_resolver, DefaultAwsEndpointResolver};
use aws_http::user_agent::AwsUserAgent;
use aws_http::AwsErrorRetryPolicy;
use aws_hyper::test_connection::TestConnection;
use aws_hyper::{Client, RetryConfig, SdkError};
use aws_hyper::{Client, RetryConfig};
use aws_sig_auth::signer::OperationSigningConfig;
use aws_types::region::Region;
use bytes::Bytes;
@@ -18,6 +18,7 @@ use smithy_http::body::SdkBody;
use smithy_http::operation;
use smithy_http::operation::Operation;
use smithy_http::response::ParseHttpResponse;
use smithy_http::result::SdkError;
use smithy_types::retry::{ErrorKind, ProvideErrorKind};
use std::convert::Infallible;
use std::error::Error;
Loading