@aws-sdk/middleware-sdk-s3 3.669.0 → 3.674.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -133,23 +133,24 @@ var regionRedirectEndpointMiddlewareOptions = {
133
133
  // src/region-redirect-middleware.ts
134
134
  function regionRedirectMiddleware(clientConfig) {
135
135
  return (next, context) => async (args) => {
136
- var _a, _b;
136
+ var _a, _b, _c;
137
137
  try {
138
138
  return await next(args);
139
139
  } catch (err) {
140
- if (clientConfig.followRegionRedirects && // 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
141
- ((_a = err == null ? void 0 : err.$metadata) == null ? void 0 : _a.httpStatusCode) === 301) {
142
- try {
143
- const actualRegion = err.$response.headers["x-amz-bucket-region"];
144
- (_b = context.logger) == null ? void 0 : _b.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
145
- context.__s3RegionRedirect = actualRegion;
146
- } catch (e) {
147
- throw new Error("Region redirect failed: " + e);
140
+ if (clientConfig.followRegionRedirects) {
141
+ if (((_a = err == null ? void 0 : err.$metadata) == null ? void 0 : _a.httpStatusCode) === 301 || // 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
142
+ ((_b = err == null ? void 0 : err.$metadata) == null ? void 0 : _b.httpStatusCode) === 400 && (err == null ? void 0 : err.name) === "IllegalLocationConstraintException") {
143
+ try {
144
+ const actualRegion = err.$response.headers["x-amz-bucket-region"];
145
+ (_c = context.logger) == null ? void 0 : _c.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
146
+ context.__s3RegionRedirect = actualRegion;
147
+ } catch (e) {
148
+ throw new Error("Region redirect failed: " + e);
149
+ }
150
+ return next(args);
148
151
  }
149
- return next(args);
150
- } else {
151
- throw err;
152
152
  }
153
+ throw err;
153
154
  }
154
155
  };
155
156
  }
@@ -5,21 +5,21 @@ export function regionRedirectMiddleware(clientConfig) {
5
5
  return await next(args);
6
6
  }
7
7
  catch (err) {
8
- if (clientConfig.followRegionRedirects &&
9
- err?.$metadata?.httpStatusCode === 301) {
10
- try {
11
- const actualRegion = err.$response.headers["x-amz-bucket-region"];
12
- context.logger?.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
13
- context.__s3RegionRedirect = actualRegion;
8
+ if (clientConfig.followRegionRedirects) {
9
+ if (err?.$metadata?.httpStatusCode === 301 ||
10
+ (err?.$metadata?.httpStatusCode === 400 && err?.name === "IllegalLocationConstraintException")) {
11
+ try {
12
+ const actualRegion = err.$response.headers["x-amz-bucket-region"];
13
+ context.logger?.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
14
+ context.__s3RegionRedirect = actualRegion;
15
+ }
16
+ catch (e) {
17
+ throw new Error("Region redirect failed: " + e);
18
+ }
19
+ return next(args);
14
20
  }
15
- catch (e) {
16
- throw new Error("Region redirect failed: " + e);
17
- }
18
- return next(args);
19
- }
20
- else {
21
- throw err;
22
21
  }
22
+ throw err;
23
23
  }
24
24
  };
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-sdk-s3",
3
- "version": "3.669.0",
3
+ "version": "3.674.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline middleware-sdk-s3",