From 9119ae6c46a3eece9c25e27142193f03229519f6 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 17 Jul 2024 11:32:01 -0400 Subject: [PATCH] chore(middleware-sdk-s3): update s3 status 200 error handling (#6232) * chore(middleware-sdk-s3): update s3 status 200 error handling * fix(middleware-sdk-s3): only check tail bytes in s3-200-errors * chore(middleware-sdk-s3): use splitStream utility function to inspect 200-error --- .../commands/AbortMultipartUploadCommand.ts | 2 + .../src/commands/CreateBucketCommand.ts | 2 + .../commands/CreateMultipartUploadCommand.ts | 2 + .../src/commands/CreateSessionCommand.ts | 2 + .../src/commands/DeleteObjectCommand.ts | 2 + .../commands/DeleteObjectTaggingCommand.ts | 2 + .../src/commands/DeleteObjectsCommand.ts | 2 + ...GetBucketAccelerateConfigurationCommand.ts | 2 + .../src/commands/GetBucketAclCommand.ts | 2 + .../GetBucketAnalyticsConfigurationCommand.ts | 2 + .../src/commands/GetBucketCorsCommand.ts | 2 + .../commands/GetBucketEncryptionCommand.ts | 2 + ...tIntelligentTieringConfigurationCommand.ts | 2 + .../GetBucketInventoryConfigurationCommand.ts | 2 + .../GetBucketLifecycleConfigurationCommand.ts | 2 + .../src/commands/GetBucketLocationCommand.ts | 2 + .../src/commands/GetBucketLoggingCommand.ts | 2 + .../GetBucketMetricsConfigurationCommand.ts | 2 + ...tBucketNotificationConfigurationCommand.ts | 2 + .../GetBucketOwnershipControlsCommand.ts | 2 + .../src/commands/GetBucketPolicyCommand.ts | 2 + .../commands/GetBucketPolicyStatusCommand.ts | 2 + .../commands/GetBucketReplicationCommand.ts | 2 + .../GetBucketRequestPaymentCommand.ts | 2 + .../src/commands/GetBucketTaggingCommand.ts | 2 + .../commands/GetBucketVersioningCommand.ts | 2 + .../src/commands/GetBucketWebsiteCommand.ts | 2 + .../src/commands/GetObjectAclCommand.ts | 2 + .../commands/GetObjectAttributesCommand.ts | 2 + .../src/commands/GetObjectLegalHoldCommand.ts | 2 + .../GetObjectLockConfigurationCommand.ts | 2 + .../src/commands/GetObjectRetentionCommand.ts | 2 + .../src/commands/GetObjectTaggingCommand.ts | 2 + .../commands/GetPublicAccessBlockCommand.ts | 2 + .../src/commands/HeadBucketCommand.ts | 2 + .../src/commands/HeadObjectCommand.ts | 3 +- ...istBucketAnalyticsConfigurationsCommand.ts | 2 + ...IntelligentTieringConfigurationsCommand.ts | 2 + ...istBucketInventoryConfigurationsCommand.ts | 2 + .../ListBucketMetricsConfigurationsCommand.ts | 2 + .../src/commands/ListBucketsCommand.ts | 2 + .../commands/ListDirectoryBucketsCommand.ts | 2 + .../commands/ListMultipartUploadsCommand.ts | 2 + .../src/commands/ListObjectVersionsCommand.ts | 2 + .../src/commands/ListObjectsCommand.ts | 2 + .../src/commands/ListObjectsV2Command.ts | 2 + .../src/commands/ListPartsCommand.ts | 2 + .../src/commands/PutObjectAclCommand.ts | 2 + .../src/commands/PutObjectCommand.ts | 3 +- .../src/commands/PutObjectLegalHoldCommand.ts | 2 + .../PutObjectLockConfigurationCommand.ts | 2 + .../src/commands/PutObjectRetentionCommand.ts | 2 + .../src/commands/PutObjectTaggingCommand.ts | 2 + .../src/commands/RestoreObjectCommand.ts | 2 + .../commands/SelectObjectContentCommand.ts | 2 + .../src/commands/UploadPartCommand.ts | 2 + .../aws/typescript/codegen/AddS3Config.java | 38 +++++++-- packages/middleware-sdk-s3/package.json | 2 + .../src/throw-200-exceptions.spec.ts | 82 +++++++++++++++---- .../src/throw-200-exceptions.ts | 80 +++++++++++++----- scripts/copy-smithy-dist-files.js | 6 +- 61 files changed, 276 insertions(+), 46 deletions(-) diff --git a/clients/client-s3/src/commands/AbortMultipartUploadCommand.ts b/clients/client-s3/src/commands/AbortMultipartUploadCommand.ts index 4b7f603bf086..b6b276f9ed09 100644 --- a/clients/client-s3/src/commands/AbortMultipartUploadCommand.ts +++ b/clients/client-s3/src/commands/AbortMultipartUploadCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -164,6 +165,7 @@ export class AbortMultipartUploadCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "AbortMultipartUpload", {}) diff --git a/clients/client-s3/src/commands/CreateBucketCommand.ts b/clients/client-s3/src/commands/CreateBucketCommand.ts index 46fc512357db..823e7d3a4066 100644 --- a/clients/client-s3/src/commands/CreateBucketCommand.ts +++ b/clients/client-s3/src/commands/CreateBucketCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getLocationConstraintPlugin } from "@aws-sdk/middleware-location-constraint"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -272,6 +273,7 @@ export class CreateBucketCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getLocationConstraintPlugin(config), ]; }) diff --git a/clients/client-s3/src/commands/CreateMultipartUploadCommand.ts b/clients/client-s3/src/commands/CreateMultipartUploadCommand.ts index 4252decfd0b2..0f5f426ddf7a 100644 --- a/clients/client-s3/src/commands/CreateMultipartUploadCommand.ts +++ b/clients/client-s3/src/commands/CreateMultipartUploadCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -358,6 +359,7 @@ export class CreateMultipartUploadCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), ]; }) diff --git a/clients/client-s3/src/commands/CreateSessionCommand.ts b/clients/client-s3/src/commands/CreateSessionCommand.ts index 1421553c52f5..8e2c06e41b6a 100644 --- a/clients/client-s3/src/commands/CreateSessionCommand.ts +++ b/clients/client-s3/src/commands/CreateSessionCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -146,6 +147,7 @@ export class CreateSessionCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "CreateSession", {}) diff --git a/clients/client-s3/src/commands/DeleteObjectCommand.ts b/clients/client-s3/src/commands/DeleteObjectCommand.ts index d2b3b5a87947..5831345ed5a4 100644 --- a/clients/client-s3/src/commands/DeleteObjectCommand.ts +++ b/clients/client-s3/src/commands/DeleteObjectCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -204,6 +205,7 @@ export class DeleteObjectCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "DeleteObject", {}) diff --git a/clients/client-s3/src/commands/DeleteObjectTaggingCommand.ts b/clients/client-s3/src/commands/DeleteObjectTaggingCommand.ts index 829a9b612bf1..5d588aa5d266 100644 --- a/clients/client-s3/src/commands/DeleteObjectTaggingCommand.ts +++ b/clients/client-s3/src/commands/DeleteObjectTaggingCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -133,6 +134,7 @@ export class DeleteObjectTaggingCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "DeleteObjectTagging", {}) diff --git a/clients/client-s3/src/commands/DeleteObjectsCommand.ts b/clients/client-s3/src/commands/DeleteObjectsCommand.ts index 413c530cf35c..d9c68912d57f 100644 --- a/clients/client-s3/src/commands/DeleteObjectsCommand.ts +++ b/clients/client-s3/src/commands/DeleteObjectsCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -305,6 +306,7 @@ export class DeleteObjectsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/GetBucketAccelerateConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketAccelerateConfigurationCommand.ts index cf9e8104e5ed..2a698e3d02ce 100644 --- a/clients/client-s3/src/commands/GetBucketAccelerateConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketAccelerateConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -110,6 +111,7 @@ export class GetBucketAccelerateConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketAccelerateConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketAclCommand.ts b/clients/client-s3/src/commands/GetBucketAclCommand.ts index a772d9247b75..edbb6ca9955f 100644 --- a/clients/client-s3/src/commands/GetBucketAclCommand.ts +++ b/clients/client-s3/src/commands/GetBucketAclCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -118,6 +119,7 @@ export class GetBucketAclCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketAcl", {}) diff --git a/clients/client-s3/src/commands/GetBucketAnalyticsConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketAnalyticsConfigurationCommand.ts index 7ecea306558d..252599e12ba8 100644 --- a/clients/client-s3/src/commands/GetBucketAnalyticsConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketAnalyticsConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -143,6 +144,7 @@ export class GetBucketAnalyticsConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketAnalyticsConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketCorsCommand.ts b/clients/client-s3/src/commands/GetBucketCorsCommand.ts index 38519995ceff..77803afc81eb 100644 --- a/clients/client-s3/src/commands/GetBucketCorsCommand.ts +++ b/clients/client-s3/src/commands/GetBucketCorsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -148,6 +149,7 @@ export class GetBucketCorsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketCors", {}) diff --git a/clients/client-s3/src/commands/GetBucketEncryptionCommand.ts b/clients/client-s3/src/commands/GetBucketEncryptionCommand.ts index 04d6dbef09d5..5f8bbc1127d9 100644 --- a/clients/client-s3/src/commands/GetBucketEncryptionCommand.ts +++ b/clients/client-s3/src/commands/GetBucketEncryptionCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -113,6 +114,7 @@ export class GetBucketEncryptionCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketEncryption", {}) diff --git a/clients/client-s3/src/commands/GetBucketIntelligentTieringConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketIntelligentTieringConfigurationCommand.ts index cf50ffd46d94..3b67985769c1 100644 --- a/clients/client-s3/src/commands/GetBucketIntelligentTieringConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketIntelligentTieringConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -133,6 +134,7 @@ export class GetBucketIntelligentTieringConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketIntelligentTieringConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketInventoryConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketInventoryConfigurationCommand.ts index 8e225c899f09..a5ee988edfa4 100644 --- a/clients/client-s3/src/commands/GetBucketInventoryConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketInventoryConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -141,6 +142,7 @@ export class GetBucketInventoryConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketInventoryConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketLifecycleConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketLifecycleConfigurationCommand.ts index c7382303849c..639138d5c604 100644 --- a/clients/client-s3/src/commands/GetBucketLifecycleConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketLifecycleConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -216,6 +217,7 @@ export class GetBucketLifecycleConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketLifecycleConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketLocationCommand.ts b/clients/client-s3/src/commands/GetBucketLocationCommand.ts index a7e257f68b87..18a195e0e65c 100644 --- a/clients/client-s3/src/commands/GetBucketLocationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketLocationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -119,6 +120,7 @@ export class GetBucketLocationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketLocation", {}) diff --git a/clients/client-s3/src/commands/GetBucketLoggingCommand.ts b/clients/client-s3/src/commands/GetBucketLoggingCommand.ts index 93b9c2e30246..07ae9ff574b2 100644 --- a/clients/client-s3/src/commands/GetBucketLoggingCommand.ts +++ b/clients/client-s3/src/commands/GetBucketLoggingCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -113,6 +114,7 @@ export class GetBucketLoggingCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketLogging", {}) diff --git a/clients/client-s3/src/commands/GetBucketMetricsConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketMetricsConfigurationCommand.ts index 6512c71fa652..e25f246a40d8 100644 --- a/clients/client-s3/src/commands/GetBucketMetricsConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketMetricsConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -136,6 +137,7 @@ export class GetBucketMetricsConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketMetricsConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketNotificationConfigurationCommand.ts b/clients/client-s3/src/commands/GetBucketNotificationConfigurationCommand.ts index 08ad4e43fd67..c431ec8b6a03 100644 --- a/clients/client-s3/src/commands/GetBucketNotificationConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketNotificationConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -160,6 +161,7 @@ export class GetBucketNotificationConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketNotificationConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetBucketOwnershipControlsCommand.ts b/clients/client-s3/src/commands/GetBucketOwnershipControlsCommand.ts index 19c71fb6b0b7..c58c121de714 100644 --- a/clients/client-s3/src/commands/GetBucketOwnershipControlsCommand.ts +++ b/clients/client-s3/src/commands/GetBucketOwnershipControlsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -102,6 +103,7 @@ export class GetBucketOwnershipControlsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketOwnershipControls", {}) diff --git a/clients/client-s3/src/commands/GetBucketPolicyCommand.ts b/clients/client-s3/src/commands/GetBucketPolicyCommand.ts index 12c259d1e901..12617faf2db4 100644 --- a/clients/client-s3/src/commands/GetBucketPolicyCommand.ts +++ b/clients/client-s3/src/commands/GetBucketPolicyCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -152,6 +153,7 @@ export class GetBucketPolicyCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketPolicy", {}) diff --git a/clients/client-s3/src/commands/GetBucketPolicyStatusCommand.ts b/clients/client-s3/src/commands/GetBucketPolicyStatusCommand.ts index ec9df74d765d..36a98fd1023c 100644 --- a/clients/client-s3/src/commands/GetBucketPolicyStatusCommand.ts +++ b/clients/client-s3/src/commands/GetBucketPolicyStatusCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -108,6 +109,7 @@ export class GetBucketPolicyStatusCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketPolicyStatus", {}) diff --git a/clients/client-s3/src/commands/GetBucketReplicationCommand.ts b/clients/client-s3/src/commands/GetBucketReplicationCommand.ts index 17e0f4c6bffc..137f5a2febe9 100644 --- a/clients/client-s3/src/commands/GetBucketReplicationCommand.ts +++ b/clients/client-s3/src/commands/GetBucketReplicationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -198,6 +199,7 @@ export class GetBucketReplicationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketReplication", {}) diff --git a/clients/client-s3/src/commands/GetBucketRequestPaymentCommand.ts b/clients/client-s3/src/commands/GetBucketRequestPaymentCommand.ts index 4561303ad9d8..930bff8ff378 100644 --- a/clients/client-s3/src/commands/GetBucketRequestPaymentCommand.ts +++ b/clients/client-s3/src/commands/GetBucketRequestPaymentCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -104,6 +105,7 @@ export class GetBucketRequestPaymentCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketRequestPayment", {}) diff --git a/clients/client-s3/src/commands/GetBucketTaggingCommand.ts b/clients/client-s3/src/commands/GetBucketTaggingCommand.ts index c7d86711ea8e..625845d3539c 100644 --- a/clients/client-s3/src/commands/GetBucketTaggingCommand.ts +++ b/clients/client-s3/src/commands/GetBucketTaggingCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -137,6 +138,7 @@ export class GetBucketTaggingCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketTagging", {}) diff --git a/clients/client-s3/src/commands/GetBucketVersioningCommand.ts b/clients/client-s3/src/commands/GetBucketVersioningCommand.ts index 9c49d7933aa2..7b93df2a6d71 100644 --- a/clients/client-s3/src/commands/GetBucketVersioningCommand.ts +++ b/clients/client-s3/src/commands/GetBucketVersioningCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -118,6 +119,7 @@ export class GetBucketVersioningCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketVersioning", {}) diff --git a/clients/client-s3/src/commands/GetBucketWebsiteCommand.ts b/clients/client-s3/src/commands/GetBucketWebsiteCommand.ts index 0498630edcbf..468d96e58f9d 100644 --- a/clients/client-s3/src/commands/GetBucketWebsiteCommand.ts +++ b/clients/client-s3/src/commands/GetBucketWebsiteCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -142,6 +143,7 @@ export class GetBucketWebsiteCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetBucketWebsite", {}) diff --git a/clients/client-s3/src/commands/GetObjectAclCommand.ts b/clients/client-s3/src/commands/GetObjectAclCommand.ts index 36d70066b7f3..e25ef4a2ec10 100644 --- a/clients/client-s3/src/commands/GetObjectAclCommand.ts +++ b/clients/client-s3/src/commands/GetObjectAclCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -192,6 +193,7 @@ export class GetObjectAclCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetObjectAcl", {}) diff --git a/clients/client-s3/src/commands/GetObjectAttributesCommand.ts b/clients/client-s3/src/commands/GetObjectAttributesCommand.ts index 6756fa7b2496..e22f181adfbd 100644 --- a/clients/client-s3/src/commands/GetObjectAttributesCommand.ts +++ b/clients/client-s3/src/commands/GetObjectAttributesCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -308,6 +309,7 @@ export class GetObjectAttributesCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), ]; }) diff --git a/clients/client-s3/src/commands/GetObjectLegalHoldCommand.ts b/clients/client-s3/src/commands/GetObjectLegalHoldCommand.ts index b21c3486a7eb..f67d14ec3041 100644 --- a/clients/client-s3/src/commands/GetObjectLegalHoldCommand.ts +++ b/clients/client-s3/src/commands/GetObjectLegalHoldCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -92,6 +93,7 @@ export class GetObjectLegalHoldCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetObjectLegalHold", {}) diff --git a/clients/client-s3/src/commands/GetObjectLockConfigurationCommand.ts b/clients/client-s3/src/commands/GetObjectLockConfigurationCommand.ts index 31b113fec11e..d704fd843bb8 100644 --- a/clients/client-s3/src/commands/GetObjectLockConfigurationCommand.ts +++ b/clients/client-s3/src/commands/GetObjectLockConfigurationCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -96,6 +97,7 @@ export class GetObjectLockConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetObjectLockConfiguration", {}) diff --git a/clients/client-s3/src/commands/GetObjectRetentionCommand.ts b/clients/client-s3/src/commands/GetObjectRetentionCommand.ts index 5427a527ad67..d9f5c3ff8a19 100644 --- a/clients/client-s3/src/commands/GetObjectRetentionCommand.ts +++ b/clients/client-s3/src/commands/GetObjectRetentionCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -93,6 +94,7 @@ export class GetObjectRetentionCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetObjectRetention", {}) diff --git a/clients/client-s3/src/commands/GetObjectTaggingCommand.ts b/clients/client-s3/src/commands/GetObjectTaggingCommand.ts index 070a938b8541..ef198b10d2af 100644 --- a/clients/client-s3/src/commands/GetObjectTaggingCommand.ts +++ b/clients/client-s3/src/commands/GetObjectTaggingCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -165,6 +166,7 @@ export class GetObjectTaggingCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetObjectTagging", {}) diff --git a/clients/client-s3/src/commands/GetPublicAccessBlockCommand.ts b/clients/client-s3/src/commands/GetPublicAccessBlockCommand.ts index ccca8d7040da..523ef0e6713d 100644 --- a/clients/client-s3/src/commands/GetPublicAccessBlockCommand.ts +++ b/clients/client-s3/src/commands/GetPublicAccessBlockCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -119,6 +120,7 @@ export class GetPublicAccessBlockCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "GetPublicAccessBlock", {}) diff --git a/clients/client-s3/src/commands/HeadBucketCommand.ts b/clients/client-s3/src/commands/HeadBucketCommand.ts index d8ff44747e27..ed54a832204a 100644 --- a/clients/client-s3/src/commands/HeadBucketCommand.ts +++ b/clients/client-s3/src/commands/HeadBucketCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -140,6 +141,7 @@ export class HeadBucketCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "HeadBucket", {}) diff --git a/clients/client-s3/src/commands/HeadObjectCommand.ts b/clients/client-s3/src/commands/HeadObjectCommand.ts index 566fe6ca1a8e..ce4487a8286b 100644 --- a/clients/client-s3/src/commands/HeadObjectCommand.ts +++ b/clients/client-s3/src/commands/HeadObjectCommand.ts @@ -1,5 +1,5 @@ // smithy-typescript generated code -import { getS3ExpiresMiddlewarePlugin } from "@aws-sdk/middleware-sdk-s3"; +import { getS3ExpiresMiddlewarePlugin, getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -297,6 +297,7 @@ export class HeadObjectCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), getS3ExpiresMiddlewarePlugin(config), ]; diff --git a/clients/client-s3/src/commands/ListBucketAnalyticsConfigurationsCommand.ts b/clients/client-s3/src/commands/ListBucketAnalyticsConfigurationsCommand.ts index 953e54aeb02a..50ec71ce0a72 100644 --- a/clients/client-s3/src/commands/ListBucketAnalyticsConfigurationsCommand.ts +++ b/clients/client-s3/src/commands/ListBucketAnalyticsConfigurationsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -155,6 +156,7 @@ export class ListBucketAnalyticsConfigurationsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListBucketAnalyticsConfigurations", {}) diff --git a/clients/client-s3/src/commands/ListBucketIntelligentTieringConfigurationsCommand.ts b/clients/client-s3/src/commands/ListBucketIntelligentTieringConfigurationsCommand.ts index 4bfc47bcce29..41f9a8856080 100644 --- a/clients/client-s3/src/commands/ListBucketIntelligentTieringConfigurationsCommand.ts +++ b/clients/client-s3/src/commands/ListBucketIntelligentTieringConfigurationsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -138,6 +139,7 @@ export class ListBucketIntelligentTieringConfigurationsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListBucketIntelligentTieringConfigurations", {}) diff --git a/clients/client-s3/src/commands/ListBucketInventoryConfigurationsCommand.ts b/clients/client-s3/src/commands/ListBucketInventoryConfigurationsCommand.ts index 3b77b3ab3c13..d4868df83606 100644 --- a/clients/client-s3/src/commands/ListBucketInventoryConfigurationsCommand.ts +++ b/clients/client-s3/src/commands/ListBucketInventoryConfigurationsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -154,6 +155,7 @@ export class ListBucketInventoryConfigurationsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListBucketInventoryConfigurations", {}) diff --git a/clients/client-s3/src/commands/ListBucketMetricsConfigurationsCommand.ts b/clients/client-s3/src/commands/ListBucketMetricsConfigurationsCommand.ts index 7627928a2a75..c6e0a69bb297 100644 --- a/clients/client-s3/src/commands/ListBucketMetricsConfigurationsCommand.ts +++ b/clients/client-s3/src/commands/ListBucketMetricsConfigurationsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -143,6 +144,7 @@ export class ListBucketMetricsConfigurationsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListBucketMetricsConfigurations", {}) diff --git a/clients/client-s3/src/commands/ListBucketsCommand.ts b/clients/client-s3/src/commands/ListBucketsCommand.ts index 657ed5f0d639..b3b1ca9e7c66 100644 --- a/clients/client-s3/src/commands/ListBucketsCommand.ts +++ b/clients/client-s3/src/commands/ListBucketsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -116,6 +117,7 @@ export class ListBucketsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListBuckets", {}) diff --git a/clients/client-s3/src/commands/ListDirectoryBucketsCommand.ts b/clients/client-s3/src/commands/ListDirectoryBucketsCommand.ts index 142dd9ed959d..7572bcf44afe 100644 --- a/clients/client-s3/src/commands/ListDirectoryBucketsCommand.ts +++ b/clients/client-s3/src/commands/ListDirectoryBucketsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -98,6 +99,7 @@ export class ListDirectoryBucketsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListDirectoryBuckets", {}) diff --git a/clients/client-s3/src/commands/ListMultipartUploadsCommand.ts b/clients/client-s3/src/commands/ListMultipartUploadsCommand.ts index 3ece88c6a542..fe1c25cfa3b8 100644 --- a/clients/client-s3/src/commands/ListMultipartUploadsCommand.ts +++ b/clients/client-s3/src/commands/ListMultipartUploadsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -327,6 +328,7 @@ export class ListMultipartUploadsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListMultipartUploads", {}) diff --git a/clients/client-s3/src/commands/ListObjectVersionsCommand.ts b/clients/client-s3/src/commands/ListObjectVersionsCommand.ts index 33a2a8eb7674..9158cf8d03a6 100644 --- a/clients/client-s3/src/commands/ListObjectVersionsCommand.ts +++ b/clients/client-s3/src/commands/ListObjectVersionsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -216,6 +217,7 @@ export class ListObjectVersionsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListObjectVersions", {}) diff --git a/clients/client-s3/src/commands/ListObjectsCommand.ts b/clients/client-s3/src/commands/ListObjectsCommand.ts index ea5eb5405855..efd76dac55dd 100644 --- a/clients/client-s3/src/commands/ListObjectsCommand.ts +++ b/clients/client-s3/src/commands/ListObjectsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -199,6 +200,7 @@ export class ListObjectsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListObjects", {}) diff --git a/clients/client-s3/src/commands/ListObjectsV2Command.ts b/clients/client-s3/src/commands/ListObjectsV2Command.ts index 71050a630e4e..a3147b84f032 100644 --- a/clients/client-s3/src/commands/ListObjectsV2Command.ts +++ b/clients/client-s3/src/commands/ListObjectsV2Command.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -240,6 +241,7 @@ export class ListObjectsV2Command extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), ]; }) .s("AmazonS3", "ListObjectsV2", {}) diff --git a/clients/client-s3/src/commands/ListPartsCommand.ts b/clients/client-s3/src/commands/ListPartsCommand.ts index a5b9d0e4c50a..7134ba96ec31 100644 --- a/clients/client-s3/src/commands/ListPartsCommand.ts +++ b/clients/client-s3/src/commands/ListPartsCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -236,6 +237,7 @@ export class ListPartsCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), ]; }) diff --git a/clients/client-s3/src/commands/PutObjectAclCommand.ts b/clients/client-s3/src/commands/PutObjectAclCommand.ts index b4f4e70abc6f..0d7f12c75a3b 100644 --- a/clients/client-s3/src/commands/PutObjectAclCommand.ts +++ b/clients/client-s3/src/commands/PutObjectAclCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -311,6 +312,7 @@ export class PutObjectAclCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/PutObjectCommand.ts b/clients/client-s3/src/commands/PutObjectCommand.ts index 470bf72fdb87..16b7228eb064 100644 --- a/clients/client-s3/src/commands/PutObjectCommand.ts +++ b/clients/client-s3/src/commands/PutObjectCommand.ts @@ -1,6 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; -import { getCheckContentLengthHeaderPlugin } from "@aws-sdk/middleware-sdk-s3"; +import { getCheckContentLengthHeaderPlugin, getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -409,6 +409,7 @@ export class PutObjectCommand extends $Command getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), getCheckContentLengthHeaderPlugin(config), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, diff --git a/clients/client-s3/src/commands/PutObjectLegalHoldCommand.ts b/clients/client-s3/src/commands/PutObjectLegalHoldCommand.ts index 80d427dfd734..1caa10b1b34c 100644 --- a/clients/client-s3/src/commands/PutObjectLegalHoldCommand.ts +++ b/clients/client-s3/src/commands/PutObjectLegalHoldCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -89,6 +90,7 @@ export class PutObjectLegalHoldCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/PutObjectLockConfigurationCommand.ts b/clients/client-s3/src/commands/PutObjectLockConfigurationCommand.ts index b1bbe0cf30a4..679df0bcf11d 100644 --- a/clients/client-s3/src/commands/PutObjectLockConfigurationCommand.ts +++ b/clients/client-s3/src/commands/PutObjectLockConfigurationCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -112,6 +113,7 @@ export class PutObjectLockConfigurationCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/PutObjectRetentionCommand.ts b/clients/client-s3/src/commands/PutObjectRetentionCommand.ts index cfa30340fb22..76311b0756fe 100644 --- a/clients/client-s3/src/commands/PutObjectRetentionCommand.ts +++ b/clients/client-s3/src/commands/PutObjectRetentionCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -92,6 +93,7 @@ export class PutObjectRetentionCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/PutObjectTaggingCommand.ts b/clients/client-s3/src/commands/PutObjectTaggingCommand.ts index 038c99507a19..9097e536cf32 100644 --- a/clients/client-s3/src/commands/PutObjectTaggingCommand.ts +++ b/clients/client-s3/src/commands/PutObjectTaggingCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -172,6 +173,7 @@ export class PutObjectTaggingCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/RestoreObjectCommand.ts b/clients/client-s3/src/commands/RestoreObjectCommand.ts index 4eebcef2f1ae..ff0dc104d6ff 100644 --- a/clients/client-s3/src/commands/RestoreObjectCommand.ts +++ b/clients/client-s3/src/commands/RestoreObjectCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; import { Command as $Command } from "@smithy/smithy-client"; @@ -386,6 +387,7 @@ export class RestoreObjectCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, requestAlgorithmMember: "ChecksumAlgorithm", diff --git a/clients/client-s3/src/commands/SelectObjectContentCommand.ts b/clients/client-s3/src/commands/SelectObjectContentCommand.ts index 04d84e8e69b4..4f3f738fb48f 100644 --- a/clients/client-s3/src/commands/SelectObjectContentCommand.ts +++ b/clients/client-s3/src/commands/SelectObjectContentCommand.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -262,6 +263,7 @@ export class SelectObjectContentCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), ]; }) diff --git a/clients/client-s3/src/commands/UploadPartCommand.ts b/clients/client-s3/src/commands/UploadPartCommand.ts index f05c94fd854f..d184287dea7f 100644 --- a/clients/client-s3/src/commands/UploadPartCommand.ts +++ b/clients/client-s3/src/commands/UploadPartCommand.ts @@ -1,5 +1,6 @@ // smithy-typescript generated code import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums"; +import { getThrow200ExceptionsPlugin } from "@aws-sdk/middleware-sdk-s3"; import { getSsecPlugin } from "@aws-sdk/middleware-ssec"; import { getEndpointPlugin } from "@smithy/middleware-endpoint"; import { getSerdePlugin } from "@smithy/middleware-serde"; @@ -292,6 +293,7 @@ export class UploadPartCommand extends $Command return [ getSerdePlugin(config, this.serialize, this.deserialize), getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + getThrow200ExceptionsPlugin(config), getSsecPlugin(config), getFlexibleChecksumsPlugin(config, { input: this.input, diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java index 857159effa70..1e31d988bee4 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java @@ -44,6 +44,8 @@ import software.amazon.smithy.model.traits.DeprecatedTrait; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.HttpHeaderTrait; +import software.amazon.smithy.model.traits.HttpPayloadTrait; +import software.amazon.smithy.model.traits.StreamingTrait; import software.amazon.smithy.typescript.codegen.LanguageTarget; import software.amazon.smithy.typescript.codegen.TypeScriptDependency; import software.amazon.smithy.typescript.codegen.TypeScriptSettings; @@ -72,12 +74,6 @@ public final class AddS3Config implements TypeScriptIntegration { "ListBuckets" ); - private static final Set EXCEPTIONS_OF_200_OPERATIONS = SetUtils.of( - "CopyObject", - "UploadPartCopy", - "CompleteMultipartUpload" - ); - private static final String CRT_NOTIFICATION = "

Note: To supply the Multi-region Access Point (MRAP) to Bucket," + " you need to install the \"@aws-sdk/signature-v4-crt\" package to your project dependencies. \n" + "For more information, please go to https://github.com/aws/aws-sdk-js-v3#known-issues

"; @@ -288,9 +284,33 @@ public List getClientPlugins() { RuntimeClientPlugin.builder() .withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "throw200Exceptions", HAS_MIDDLEWARE) - .operationPredicate( - (m, s, o) -> EXCEPTIONS_OF_200_OPERATIONS.contains(o.getId().getName(s)) - && isS3(s)) + .operationPredicate((m, s, o) -> { + if (!isS3(s)) { + return false; + } + Optional output = o.getOutput(); + if (output.isPresent()) { + Shape outputShape = m.expectShape(output.get()); + boolean hasStreamingBlobOutputPayload = outputShape.getAllMembers().values().stream().anyMatch( + memberShape -> { + boolean isPayload = memberShape.hasTrait(HttpPayloadTrait.class); + if (!isPayload) { + return false; + } + Shape shape = m.expectShape(memberShape.getTarget()); + boolean isBlob = shape.isBlobShape(); + if (!isBlob) { + return false; + } + return shape.hasTrait(StreamingTrait.class); + } + ); + if (hasStreamingBlobOutputPayload) { + return false; + } + } + return output.isPresent(); + }) .build(), RuntimeClientPlugin.builder() .withConventions(AwsDependency.ADD_EXPECT_CONTINUE.dependency, "AddExpectContinue", diff --git a/packages/middleware-sdk-s3/package.json b/packages/middleware-sdk-s3/package.json index c587778955bb..86dcc557128c 100644 --- a/packages/middleware-sdk-s3/package.json +++ b/packages/middleware-sdk-s3/package.json @@ -31,6 +31,8 @@ "@smithy/smithy-client": "^3.1.8", "@smithy/types": "^3.3.0", "@smithy/util-config-provider": "^3.0.0", + "@smithy/util-stream": "^3.0.6", + "@smithy/util-utf8": "^3.0.0", "tslib": "^2.6.2" }, "devDependencies": { diff --git a/packages/middleware-sdk-s3/src/throw-200-exceptions.spec.ts b/packages/middleware-sdk-s3/src/throw-200-exceptions.spec.ts index be83c73503a1..031631803c4c 100644 --- a/packages/middleware-sdk-s3/src/throw-200-exceptions.spec.ts +++ b/packages/middleware-sdk-s3/src/throw-200-exceptions.spec.ts @@ -1,15 +1,14 @@ import { HttpRequest, HttpResponse } from "@smithy/protocol-http"; +import { toUtf8 } from "@smithy/util-utf8"; +import { Readable } from "stream"; import { throw200ExceptionsMiddleware } from "./throw-200-exceptions"; describe("throw200ExceptionsMiddlewareOptions", () => { const mockNextHandler = jest.fn(); - const mockStreamCollector = jest.fn(); - const mockUtf8Encoder = jest.fn(); const mockResponse = jest.fn(); const mockConfig = { - streamCollector: mockStreamCollector, - utf8Encoder: mockUtf8Encoder, + utf8Encoder: toUtf8, }; beforeEach(() => { @@ -17,9 +16,6 @@ describe("throw200ExceptionsMiddlewareOptions", () => { }); describe("tests for statusCode < 200 and >= 300", () => { - mockStreamCollector.mockResolvedValue(Buffer.from("")); - mockUtf8Encoder.mockReturnValue(""); - it.each([199, 300])("results for statusCode %i", async (statusCode) => { mockNextHandler.mockReturnValue({ response: mockResponse, @@ -39,16 +35,16 @@ describe("throw200ExceptionsMiddlewareOptions", () => { it("should throw if response body is empty", async () => { expect.assertions(3); - mockStreamCollector.mockResolvedValue(Buffer.from("")); - mockUtf8Encoder.mockReturnValue(""); mockNextHandler.mockReturnValue({ response: new HttpResponse({ statusCode: 200, headers: {}, - body: "", + body: Readable.from(Buffer.from("")), }), }); - const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any); + const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, { + commandName: "CompleteMultipartUploadCommand", + } as any); try { await handler({ input: {}, @@ -71,13 +67,11 @@ describe("throw200ExceptionsMiddlewareOptions", () => { 656c76696e6727732072657175657374 Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg== `; - mockStreamCollector.mockResolvedValue(Buffer.from(errorBody)); - mockUtf8Encoder.mockReturnValue(errorBody); mockNextHandler.mockReturnValue({ response: new HttpResponse({ statusCode: 200, headers: {}, - body: "", + body: Readable.from(Buffer.from(errorBody)), }), }); const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any); @@ -91,5 +85,65 @@ describe("throw200ExceptionsMiddlewareOptions", () => { // @ts-ignore expect(response.statusCode).toBeGreaterThanOrEqual(400); }); + + it("should not throw if the Error tag is not the top XML element", async () => { + const errorBody = ` + + + sample1.txt + + + sample2.txt + AccessDenied + Access Denied + +`; + mockNextHandler.mockReturnValue({ + response: new HttpResponse({ + statusCode: 200, + headers: {}, + body: Readable.from(Buffer.from(errorBody)), + }), + }); + const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any); + const { response } = await handler({ + input: {}, + request: new HttpRequest({ + hostname: "s3.us-east-1.amazonaws.com", + }), + }); + expect(HttpResponse.isInstance(response)).toBe(true); + // @ts-ignore + expect(response.statusCode).toEqual(200); + }); + + /** + * This is an exception to the specification. We cannot afford to read + * a streaming body for its entire duration just to check for an extremely unlikely + * terminating XML tag if the stream is very long. + */ + it("should not throw if the Error tag is on an excessively long body", async () => { + const errorBody = ` + + ${"a".repeat(3000)} +`; + mockNextHandler.mockReturnValue({ + response: new HttpResponse({ + statusCode: 200, + headers: {}, + body: Readable.from(Buffer.from(errorBody)), + }), + }); + const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any); + const { response } = await handler({ + input: {}, + request: new HttpRequest({ + hostname: "s3.us-east-1.amazonaws.com", + }), + }); + expect(HttpResponse.isInstance(response)).toBe(true); + // @ts-ignore + expect(response.statusCode).toEqual(200); + }); }); }); diff --git a/packages/middleware-sdk-s3/src/throw-200-exceptions.ts b/packages/middleware-sdk-s3/src/throw-200-exceptions.ts index 08b4ca18c8ab..451efa52833c 100644 --- a/packages/middleware-sdk-s3/src/throw-200-exceptions.ts +++ b/packages/middleware-sdk-s3/src/throw-200-exceptions.ts @@ -1,11 +1,34 @@ import { HttpResponse } from "@smithy/protocol-http"; -import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions, StreamCollector } from "@smithy/types"; +import { + DeserializeMiddleware, + Encoder, + HandlerExecutionContext, + Pluggable, + RelativeMiddlewareOptions, + StreamCollector, +} from "@smithy/types"; +import { headStream, splitStream } from "@smithy/util-stream"; type PreviouslyResolved = { - streamCollector: StreamCollector; utf8Encoder: Encoder; }; +/** + * @internal + */ +const THROW_IF_EMPTY_BODY: Record = { + CopyObjectCommand: true, + UploadPartCopyCommand: true, + CompleteMultipartUploadCommand: true, +}; + +/** + * @internal + * We will check at most this many bytes from the stream when looking for + * an error-like 200 status. + */ +const MAX_BYTES_TO_INSPECT = 3000; + /** * In case of an internal error/terminated connection, S3 operations may return 200 errors. CopyObject, UploadPartCopy, * CompleteMultipartUpload may return empty payload or payload with only xml Preamble. @@ -13,45 +36,62 @@ type PreviouslyResolved = { */ export const throw200ExceptionsMiddleware = (config: PreviouslyResolved): DeserializeMiddleware => - (next) => + (next, context: HandlerExecutionContext) => async (args) => { const result = await next(args); const { response } = result; - if (!HttpResponse.isInstance(response)) return result; - const { statusCode, body } = response; - if (statusCode < 200 || statusCode >= 300) return result; + if (!HttpResponse.isInstance(response)) { + return result; + } + const { statusCode, body: sourceBody } = response; + if (statusCode < 200 || statusCode >= 300) { + return result; + } + + let bodyCopy = sourceBody; + let body = sourceBody; + + if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) { + [bodyCopy, body] = await splitStream(sourceBody); + } + // restore split body to the response for deserialization. + response.body = body; + + const bodyBytes: Uint8Array = await collectBody(bodyCopy, { + streamCollector: async (stream: any) => { + return headStream(stream, MAX_BYTES_TO_INSPECT); + }, + }); + const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16)); - // Throw 2XX response that's either an error or has empty body. - const bodyBytes = await collectBody(body, config); - const bodyString = await collectBodyString(bodyBytes, config); - if (bodyBytes.length === 0) { + // Throw on 200 response with empty body, legacy behavior allowlist. + if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName!]) { const err = new Error("S3 aborted request"); err.name = "InternalError"; throw err; } - if (bodyString && bodyString.match("")) { + // Generalized throw-on-200 for top level Error element and non-streaming response. + if (bodyStringTail && bodyStringTail.endsWith("")) { // Set the error code to 4XX so that error deserializer can parse them response.statusCode = 400; } - // Body stream is consumed and paused at this point. So replace the response.body to the collected bytes. - // So that the deserializer can consume the body as normal. - response.body = bodyBytes; return result; }; -// Collect low-level response body stream to Uint8Array. -const collectBody = (streamBody: any = new Uint8Array(), context: PreviouslyResolved): Promise => { +/** + * @internal + */ +const collectBody = ( + streamBody: any = new Uint8Array(), + context: { streamCollector: StreamCollector } +): Promise => { if (streamBody instanceof Uint8Array) { return Promise.resolve(streamBody); } return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array()); }; -// Encode Uint8Array data into string with utf-8. -const collectBodyString = (streamBody: any, context: PreviouslyResolved): Promise => - collectBody(streamBody, context).then((body) => context.utf8Encoder(body)); - /** * @internal */ diff --git a/scripts/copy-smithy-dist-files.js b/scripts/copy-smithy-dist-files.js index 90f6fdcab809..f6fa60329ed0 100644 --- a/scripts/copy-smithy-dist-files.js +++ b/scripts/copy-smithy-dist-files.js @@ -13,9 +13,13 @@ const smithyPackages = path.join(aws, "smithy-typescript", "packages"); const node_modules = path.join(__dirname, "..", "node_modules"); const localSmithyPkgs = fs.readdirSync(path.join(node_modules, "@smithy")); +const adjacentSmithyPkgs = fs.readdirSync(smithyPackages); (async () => { - for (const smithyPkg of localSmithyPkgs) { + for (const smithyPkg of [...localSmithyPkgs, ...adjacentSmithyPkgs]) { + if (!fs.existsSync(path.join(smithyPackages, smithyPkg, "dist-cjs"))) { + continue; + } await Promise.all([ spawnProcess("cp", [ "-r",