Skip to content

Commit 6af2361

Browse files
cpyle0819rlhagerm
authored andcommitted
JavaScript (v3): S3 - Use a more educational error for PutObject example.
1 parent faf1006 commit 6af2361

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

javascriptv3/example_code/s3/actions/put-object.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
* @param {{ bucketName: string, key: string, filePath: string }}
1616
*/
1717
export const main = async ({ bucketName, key, filePath }) => {
18-
console.log(filePath);
1918
const client = new S3Client({});
2019
const command = new PutObjectCommand({
2120
Bucket: bucketName,
@@ -29,10 +28,12 @@ export const main = async ({ bucketName, key, filePath }) => {
2928
} catch (caught) {
3029
if (
3130
caught instanceof S3ServiceException &&
32-
caught.name === "NoSuchBucket"
31+
caught.name === "EntityTooLarge"
3332
) {
3433
console.error(
35-
`Error from S3 while uploading object to ${bucketName}. The bucket doesn't exist.`,
34+
`Error from S3 while uploading object to ${bucketName}. \
35+
The object was too large. To upload objects larger than 5GB, use the S3 console (160GB max) \
36+
or the multipart upload API (5TB max).`,
3637
);
3738
} else if (caught instanceof S3ServiceException) {
3839
console.error(

javascriptv3/example_code/s3/tests/put-object.unit.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("put-object", () => {
4141

4242
it("should log a relevant error when the bucket doesn't exist", async () => {
4343
const error = new S3ServiceException("The specified bucket does not exist");
44-
error.name = "NoSuchBucket";
44+
error.name = "EntityTooLarge";
4545
const bucketName = "amzn-s3-demo-bucket";
4646
send.mockRejectedValueOnce(error);
4747

@@ -54,7 +54,9 @@ describe("put-object", () => {
5454
});
5555

5656
expect(spy).toHaveBeenCalledWith(
57-
`Error from S3 while uploading object to ${bucketName}. The bucket doesn't exist.`,
57+
`Error from S3 while uploading object to ${bucketName}. \
58+
The object was too large. To upload objects larger than 5GB, use the S3 console (160GB max) \
59+
or the multipart upload API (5TB max).`,
5860
);
5961
});
6062

0 commit comments

Comments
 (0)