Skip to content

Commit ed0bec0

Browse files
committed
fix(middleware-sdk-s3): only check tail bytes in s3-200-errors
1 parent bceac19 commit ed0bec0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/middleware-sdk-s3/src/throw-200-exceptions.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const throw200ExceptionsMiddleware =
4141
return result;
4242
}
4343

44-
const bodyBytes = await collectBody(body, config);
45-
const bodyString = await collectBodyString(bodyBytes, config);
44+
const bodyBytes: Uint8Array = await collectBody(body, config);
45+
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
4646

4747
// Throw on 200 response with empty body, legacy behavior allowlist.
4848
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName!]) {
@@ -51,7 +51,7 @@ export const throw200ExceptionsMiddleware =
5151
throw err;
5252
}
5353
// Generalized throw-on-200 for top level Error element and non-streaming response.
54-
if (bodyString && bodyString.endsWith("</Error>")) {
54+
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
5555
// Set the error code to 4XX so that error deserializer can parse them
5656
response.statusCode = 400;
5757
}
@@ -70,10 +70,6 @@ const collectBody = (streamBody: any = new Uint8Array(), context: PreviouslyReso
7070
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
7171
};
7272

73-
// Encode Uint8Array data into string with utf-8.
74-
const collectBodyString = (streamBody: any, context: PreviouslyResolved): Promise<string> =>
75-
collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
76-
7773
/**
7874
* @internal
7975
*/

scripts/copy-smithy-dist-files.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ const smithyPackages = path.join(aws, "smithy-typescript", "packages");
1313
const node_modules = path.join(__dirname, "..", "node_modules");
1414

1515
const localSmithyPkgs = fs.readdirSync(path.join(node_modules, "@smithy"));
16+
const adjacentSmithyPkgs = fs.readdirSync(smithyPackages);
1617

1718
(async () => {
18-
for (const smithyPkg of localSmithyPkgs) {
19+
for (const smithyPkg of [...localSmithyPkgs, ...adjacentSmithyPkgs]) {
20+
if (!fs.existsSync(path.join(smithyPackages, smithyPkg, "dist-cjs"))) {
21+
continue;
22+
}
1923
await Promise.all([
2024
spawnProcess("cp", [
2125
"-r",

0 commit comments

Comments
 (0)