Skip to content

Commit 581dfb9

Browse files
committed
fix(middleware-sdk-s3): handle cross-region redirects for HeadBucket with 400 status
1 parent b3364f7 commit 581dfb9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/middleware-sdk-s3/src/region-redirect-middleware.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export function regionRedirectMiddleware(clientConfig: PreviouslyResolved): Init
3939
if (
4040
err?.$metadata?.httpStatusCode === 301 ||
4141
// err.name === "PermanentRedirect" && --> removing the error name check, as that allows for HEAD operations (which have the 301 status code, but not the same error name) to be covered for region redirection as well
42-
(err?.$metadata?.httpStatusCode === 400 && err?.name === "IllegalLocationConstraintException")
42+
(err?.$metadata?.httpStatusCode === 400 && err?.name === "IllegalLocationConstraintException") ||
43+
(err?.$metadata?.httpStatusCode === 400 &&
44+
context.commandName === "HeadBucketCommand" &&
45+
err?.$response?.headers?.["x-amz-bucket-region"])
4346
) {
4447
try {
4548
const actualRegion = err.$response.headers["x-amz-bucket-region"];

0 commit comments

Comments
 (0)