@aws-sdk/middleware-sdk-s3
Advanced tools
Comparing version 3.614.0 to 3.616.0
@@ -444,13 +444,32 @@ "use strict"; | ||
var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next) => async (args) => { | ||
var import_util_stream = require("@smithy/util-stream"); | ||
var THROW_IF_EMPTY_BODY = { | ||
CopyObjectCommand: true, | ||
UploadPartCopyCommand: true, | ||
CompleteMultipartUploadCommand: true | ||
}; | ||
var MAX_BYTES_TO_INSPECT = 3e3; | ||
var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => { | ||
const result = await next(args); | ||
const { response } = result; | ||
if (!import_protocol_http.HttpResponse.isInstance(response)) | ||
if (!import_protocol_http.HttpResponse.isInstance(response)) { | ||
return result; | ||
const { statusCode, body } = response; | ||
if (statusCode < 200 || statusCode >= 300) | ||
} | ||
const { statusCode, body: sourceBody } = response; | ||
if (statusCode < 200 || statusCode >= 300) { | ||
return result; | ||
const bodyBytes = await collectBody(body, config); | ||
const bodyString = await collectBodyString(bodyBytes, config); | ||
if (bodyBytes.length === 0) { | ||
} | ||
let bodyCopy = sourceBody; | ||
let body = sourceBody; | ||
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) { | ||
[bodyCopy, body] = await (0, import_util_stream.splitStream)(sourceBody); | ||
} | ||
response.body = body; | ||
const bodyBytes = await collectBody(bodyCopy, { | ||
streamCollector: async (stream) => { | ||
return (0, import_util_stream.headStream)(stream, MAX_BYTES_TO_INSPECT); | ||
} | ||
}); | ||
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16)); | ||
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) { | ||
const err = new Error("S3 aborted request"); | ||
@@ -460,6 +479,5 @@ err.name = "InternalError"; | ||
} | ||
if (bodyString && bodyString.match("<Error>")) { | ||
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) { | ||
response.statusCode = 400; | ||
} | ||
response.body = bodyBytes; | ||
return result; | ||
@@ -473,3 +491,2 @@ }, "throw200ExceptionsMiddleware"); | ||
}, "collectBody"); | ||
var collectBodyString = /* @__PURE__ */ __name((streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body)), "collectBodyString"); | ||
var throw200ExceptionsMiddlewareOptions = { | ||
@@ -476,0 +493,0 @@ relation: "after", |
import { HttpResponse } from "@smithy/protocol-http"; | ||
export const throw200ExceptionsMiddleware = (config) => (next) => async (args) => { | ||
import { headStream, splitStream } from "@smithy/util-stream"; | ||
const THROW_IF_EMPTY_BODY = { | ||
CopyObjectCommand: true, | ||
UploadPartCopyCommand: true, | ||
CompleteMultipartUploadCommand: true, | ||
}; | ||
const MAX_BYTES_TO_INSPECT = 3000; | ||
export const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => { | ||
const result = await next(args); | ||
const { response } = result; | ||
if (!HttpResponse.isInstance(response)) | ||
if (!HttpResponse.isInstance(response)) { | ||
return result; | ||
const { statusCode, body } = response; | ||
if (statusCode < 200 || statusCode >= 300) | ||
} | ||
const { statusCode, body: sourceBody } = response; | ||
if (statusCode < 200 || statusCode >= 300) { | ||
return result; | ||
const bodyBytes = await collectBody(body, config); | ||
const bodyString = await collectBodyString(bodyBytes, config); | ||
if (bodyBytes.length === 0) { | ||
} | ||
let bodyCopy = sourceBody; | ||
let body = sourceBody; | ||
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) { | ||
[bodyCopy, body] = await splitStream(sourceBody); | ||
} | ||
response.body = body; | ||
const bodyBytes = await collectBody(bodyCopy, { | ||
streamCollector: async (stream) => { | ||
return headStream(stream, MAX_BYTES_TO_INSPECT); | ||
}, | ||
}); | ||
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16)); | ||
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) { | ||
const err = new Error("S3 aborted request"); | ||
@@ -17,6 +36,5 @@ err.name = "InternalError"; | ||
} | ||
if (bodyString && bodyString.match("<Error>")) { | ||
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) { | ||
response.statusCode = 400; | ||
} | ||
response.body = bodyBytes; | ||
return result; | ||
@@ -30,3 +48,2 @@ }; | ||
}; | ||
const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body)); | ||
export const throw200ExceptionsMiddlewareOptions = { | ||
@@ -33,0 +50,0 @@ relation: "after", |
@@ -1,4 +0,3 @@ | ||
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions, StreamCollector } from "@smithy/types"; | ||
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions } from "@smithy/types"; | ||
type PreviouslyResolved = { | ||
streamCollector: StreamCollector; | ||
utf8Encoder: Encoder; | ||
@@ -5,0 +4,0 @@ }; |
@@ -6,6 +6,4 @@ import { | ||
RelativeMiddlewareOptions, | ||
StreamCollector, | ||
} from "@smithy/types"; | ||
type PreviouslyResolved = { | ||
streamCollector: StreamCollector; | ||
utf8Encoder: Encoder; | ||
@@ -12,0 +10,0 @@ }; |
{ | ||
"name": "@aws-sdk/middleware-sdk-s3", | ||
"version": "3.614.0", | ||
"version": "3.616.0", | ||
"scripts": { | ||
@@ -29,7 +29,9 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"@smithy/node-config-provider": "^3.1.4", | ||
"@smithy/protocol-http": "^4.0.3", | ||
"@smithy/signature-v4": "^3.1.2", | ||
"@smithy/smithy-client": "^3.1.7", | ||
"@smithy/protocol-http": "^4.0.4", | ||
"@smithy/signature-v4": "^4.0.0", | ||
"@smithy/smithy-client": "^3.1.8", | ||
"@smithy/types": "^3.3.0", | ||
"@smithy/util-config-provider": "^3.0.0", | ||
"@smithy/util-stream": "^3.1.0", | ||
"@smithy/util-utf8": "^3.0.0", | ||
"tslib": "^2.6.2" | ||
@@ -36,0 +38,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80244
1667
11
+ Added@smithy/util-stream@^3.1.0
+ Added@smithy/util-utf8@^3.0.0
+ Added@smithy/signature-v4@4.1.3(transitive)
- Removed@smithy/signature-v4@3.1.2(transitive)
Updated@smithy/protocol-http@^4.0.4
Updated@smithy/signature-v4@^4.0.0
Updated@smithy/smithy-client@^3.1.8