-
Notifications
You must be signed in to change notification settings - Fork 647
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
After we've upgraded minor @aws-sdk/client-s3 version from 3.930.0 -> 3.931.0
We started getting errors which related to the fact that our code is not handling correctly the errors from the sdk.
Till now on 304/404 error codes we have got an S3ServiceException instance where after the upgrade this is not the situation no more.
Example of our code till now that worked, and after the upgrade it no longer answer true on the - error instanceof S3ServiceException condition . the error does contain the correct status code error.$metadata?.httpStatusCode but this broke our code due to this behaviour.
function handleError(error: any, fileName: string, raiseErrorOnNotFound = true) {
if (error instanceof S3ServiceException) {
if (error.$metadata?.httpStatusCode === 304) {
return { status: 'NOT_MODIFIED' };
}
if (error.$metadata?.httpStatusCode === 404) {
if (raiseErrorOnNotFound) {
throw error;
}
return { status: 'NOT_FOUND' };
}
}
throw error;
}
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/client-s3@3.931.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.12.2
Reproduction Steps
- use @aws-sdk/client-s3@3.930.0
- download non exist file (same for 304 with sending existing ifNonMatch etag)
- status returned
- upgrade @aws-sdk/client-s3@3.931.0
- fetch the file - error is thrown
async function fetchFile(bucketName: string, filename:string, lastEtag: string){
const downloadCommand = new GetObjectCommand({
Bucket: bucketName,
Key: filename,
IfNoneMatch: lastEtag,
});
try{
const downloadResponse = await s3Client.send(downloadCommand);
} catch (error: any) {
if (error instanceof S3ServiceException) {
if (error.$metadata?.httpStatusCode === 304 || error.$metadata?.httpStatusCode === 404) {
return 'as-expected';
}
}
throw error;
}
}
Observed Behavior
failed to fetch from S3 Error: Unknown
at ProtocolLib.getErrorSchemaOrThrowBaseException (/app/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js:71:63)
at AwsRestXmlProtocol.handleError (/app/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js:1610:65)
at AwsRestXmlProtocol.deserializeResponse (/app/node_modules/@aws-sdk/core/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js:301:24)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at /app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js:26:24
at /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:386:20
at /app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/middleware-retry/dist-cjs/index.js:254:46
at /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:63:28
at /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:90:20
at /app/node_modules/@aws-sdk/client-s3/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:5:26
...
...
'$metadata': {
httpStatusCode: 304,
requestId: 'YMAGTEYBCZATMZAN',
extendedRequestId: 'SkNgUIzCWTxHJ5c/IjKSR4Dp6Blo0Lf8OikHDWNqVKFEFMTS8uVwAMBZx9uWYS5+H65njWrZSv1KrjHPUQSNZODqtQ0Tf/l5y00UyKK7wD0=',
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
'$fault': 'client'
Expected Behavior
keep behaviour as expected - all errors from aws-sdk should be of type
S3ServiceException
Possible Solution
No response
Additional Information/Context
No response