File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed
packages/middleware-sdk-s3/src Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -39,19 +39,20 @@ export function regionRedirectMiddleware(clientConfig: PreviouslyResolved): Init
3939 const statusCode = err ?. $metadata ?. httpStatusCode ;
4040 const isHeadBucket = context . commandName === "HeadBucketCommand" ;
4141 const bucketRegionHeader = err ?. $response ?. headers ?. [ "x-amz-bucket-region" ] ;
42- if (
43- statusCode === 301 ||
44- ( statusCode === 400 &&
45- ( err ?. name === "IllegalLocationConstraintException" || ( isHeadBucket && bucketRegionHeader ) ) )
46- ) {
47- try {
48- const actualRegion = bucketRegionHeader ;
49- context . logger ?. debug ( `Redirecting from ${ await clientConfig . region ( ) } to ${ actualRegion } ` ) ;
50- context . __s3RegionRedirect = actualRegion ;
51- } catch ( e ) {
52- throw new Error ( "Region redirect failed: " + e ) ;
42+ if ( bucketRegionHeader ) {
43+ if (
44+ statusCode === 301 ||
45+ ( statusCode === 400 && ( err ?. name === "IllegalLocationConstraintException" || isHeadBucket ) )
46+ ) {
47+ try {
48+ const actualRegion = bucketRegionHeader ;
49+ context . logger ?. debug ( `Redirecting from ${ await clientConfig . region ( ) } to ${ actualRegion } ` ) ;
50+ context . __s3RegionRedirect = actualRegion ;
51+ } catch ( e ) {
52+ throw new Error ( "Region redirect failed: " + e ) ;
53+ }
54+ return next ( args ) ;
5355 }
54- return next ( args ) ;
5556 }
5657 }
5758 throw err ;
You can’t perform that action at this time.
0 commit comments