From 6a92568b40a545c148ffca169766d006df2ab16c Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 3 Jun 2021 15:45:39 -0400 Subject: [PATCH] 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. --- .../rustsdk/customize/s3/S3Decorator.kt | 16 ++++++++++--- aws/sdk/aws-models/s3-tests.smithy | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 aws/sdk/aws-models/s3-tests.smithy diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt index 689e62a33..a4d0c7c8a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt @@ -68,10 +68,20 @@ class S3(protocolConfig: ProtocolConfig) : RestXml(protocolConfig) { ) { rustTemplate( """ - let base_err = #{base_errors}::parse_generic_error(response.body().as_ref())?; - Ok(#{s3_errors}::parse_extended_error(base_err, &response)) + 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) ) } } diff --git a/aws/sdk/aws-models/s3-tests.smithy b/aws/sdk/aws-models/s3-tests.smithy new file mode 100644 index 000000000..3cca54df4 --- /dev/null +++ b/aws/sdk/aws-models/s3-tests.smithy @@ -0,0 +1,23 @@ +$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" + } + } +]) -- GitLab