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

fix s3 head object errors (#460)

s3 head object and head bucket can both return 404 with no body. This requires a special error handling case to avoid attempting to parse the body as XML.
parent c01245fb
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -68,10 +68,20 @@ class S3(protocolConfig: ProtocolConfig) : RestXml(protocolConfig) {
            ) {
                rustTemplate(
                    """
                    if response.body().is_empty() {
                        let mut err = #{Error}::builder();
                        if response.status().as_u16() == 404 {
                            err.code("NotFound");
                        }
                        Ok(err.build())
                    } else {
                        let base_err = #{base_errors}::parse_generic_error(response.body().as_ref())?;
                        Ok(#{s3_errors}::parse_extended_error(base_err, &response))
                    }
                """,
                    "base_errors" to restXmlErrors, "s3_errors" to AwsRuntimeType.S3Errors
                    "base_errors" to restXmlErrors,
                    "s3_errors" to AwsRuntimeType.S3Errors,
                    "Error" to RuntimeType.GenericError(runtimeConfig)
                )
            }
        }
+23 −0
Original line number Diff line number Diff line
$version: "1.0"

namespace com.amazonaws.s3
use smithy.test#httpResponseTests

apply NotFound @httpResponseTests([
    {
        id: "HeadObjectEmptyBody",
        documentation: "This test case validates https://github.com/awslabs/smithy-rs/issues/456",
        params: {
        },
        body: "",
        protocol: "aws.protocols#restXml",
        code: 404,
        headers: {
            "x-amz-request-id": "GRZ6BZ468DF52F2E",
            "x-amz-id-2": "UTniwu6QmCIjVeuK2ZfeWBOnu7SqMQOS3Vac6B/K4H2ZCawYUl+nDbhGTImuyhZ5DFiojR3Kcz4=",
            "content-type": "application/xml",
            "date": "Thu, 03 Jun 2021 04:05:52 GMT",
            "server": "AmazonS3"
        }
    }
])