diff --git a/.changes/ab40d3c7-4701-47ee-87f5-985d68db8b7f.json b/.changes/ab40d3c7-4701-47ee-87f5-985d68db8b7f.json new file mode 100644 index 00000000000..f3dd08eb9b4 --- /dev/null +++ b/.changes/ab40d3c7-4701-47ee-87f5-985d68db8b7f.json @@ -0,0 +1,8 @@ +{ + "id": "ab40d3c7-4701-47ee-87f5-985d68db8b7f", + "type": "bugfix", + "description": "Include more information when retry strategy halts early due to token bucket capacity errors", + "issues": [ + "awslabs/aws-sdk-kotlin#1321" + ] +} \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt index d9e80a59f30..cde0f078d26 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt @@ -48,16 +48,8 @@ class S3ErrorMetadataIntegration : KotlinIntegration { } } - // SectionWriter to override the default sdkErrorMetadata and displayMetadata for S3's version + // SectionWriter to override the default sdkErrorMetadata for S3's version private val addSdkErrorMetadataWriter = AppendingSectionWriter { writer -> - writer - .write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()") - .write("") - .withBlock("override val displayMetadata: List", "") { - withBlock("get() =", "") { - write("super.displayMetadata + ") - write("""listOfNotNull(sdkErrorMetadata.requestId2?.let { "Extended request ID: ${'$'}it" })""") - } - } + writer.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()") } } diff --git a/services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt b/services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt index 45074546fcd..4b25d912783 100644 --- a/services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt +++ b/services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt @@ -7,9 +7,12 @@ package aws.sdk.kotlin.services.s3.internal import aws.sdk.kotlin.runtime.AwsServiceException import aws.sdk.kotlin.services.s3.model.S3ErrorMetadata import aws.sdk.kotlin.services.s3.model.S3Exception +import aws.smithy.kotlin.runtime.ClientErrorContext +import aws.smithy.kotlin.runtime.ErrorMetadata import aws.smithy.kotlin.runtime.ServiceErrorMetadata import aws.smithy.kotlin.runtime.awsprotocol.AwsErrorDetails import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata +import aws.smithy.kotlin.runtime.collections.appendValue import aws.smithy.kotlin.runtime.collections.setIfValueNotNull import aws.smithy.kotlin.runtime.http.response.HttpResponse import aws.smithy.kotlin.runtime.serde.xml.data @@ -33,12 +36,22 @@ internal data class S3ErrorDetails( */ internal fun setS3ErrorMetadata(exception: Any, response: HttpResponse, errorDetails: S3ErrorDetails?) { setAseErrorMetadata(exception, response, errorDetails) + if (exception is AwsServiceException) { exception.sdkErrorMetadata.attributes.setIfValueNotNull(ServiceErrorMetadata.RequestId, errorDetails?.requestId) } + if (exception is S3Exception) { - val requestId2 = errorDetails?.requestId2 ?: response.headers[X_AMZN_REQUEST_ID_2_HEADER] - exception.sdkErrorMetadata.attributes.setIfValueNotNull(S3ErrorMetadata.RequestId2, requestId2) + (errorDetails?.requestId2 ?: response.headers[X_AMZN_REQUEST_ID_2_HEADER])?.let { requestId2 -> + with(exception.sdkErrorMetadata) { + attributes.setIfValueNotNull(S3ErrorMetadata.RequestId2, requestId2) + + attributes.appendValue( + ErrorMetadata.ClientContext, + ClientErrorContext("Extended request ID", requestId2), + ) + } + } } }