Skip to content

Commit 8fb6f0e

Browse files
committed
fix: use HeadBucketCommand to verify bucket existence
1 parent 0f8e404 commit 8fb6f0e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const {
66
S3Client,
7+
HeadBucketCommand,
78
CreateBucketCommand,
89
PutObjectCommand,
910
DeleteObjectCommand,
@@ -112,13 +113,18 @@ class S3Adapter {
112113
}
113114

114115
try {
115-
await this._s3Client.send(new CreateBucketCommand({ Bucket: this._bucket }));
116+
await this._s3Client.send(new HeadBucketCommand({ Bucket: this._bucket }));
116117
this._hasBucket = true;
117-
} catch (error) {
118-
if (error.name === 'BucketAlreadyExists' || error.name === 'BucketAlreadyOwnedByYou') {
118+
} catch {
119+
try {
120+
await this._s3Client.send(new CreateBucketCommand({ Bucket: this._bucket }));
119121
this._hasBucket = true;
120-
} else {
121-
throw error;
122+
} catch (error) {
123+
if (error.name === 'BucketAlreadyExists' || error.name === 'BucketAlreadyOwnedByYou') {
124+
this._hasBucket = true;
125+
} else {
126+
throw error;
127+
}
122128
}
123129
}
124130
}

0 commit comments

Comments
 (0)