feat: improve the error handling in s3

This commit is contained in:
tdurieux
2023-02-22 08:39:23 +01:00
parent 7dbfdb3056
commit b6049c4ed2
+4 -10
View File
@@ -59,15 +59,7 @@ export default class S3Storage implements StorageBase {
/** @override */ /** @override */
async mk(dir: string): Promise<void> { async mk(dir: string): Promise<void> {
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set"); // no need to create folder on S3
if (dir && dir[dir.length - 1] != "/") dir = dir + "/";
await this.client
.putObject({
Bucket: config.S3_BUCKET,
Key: dir,
})
.promise();
} }
/** @override */ /** @override */
@@ -77,6 +69,7 @@ export default class S3Storage implements StorageBase {
.listObjectsV2({ .listObjectsV2({
Bucket: config.S3_BUCKET, Bucket: config.S3_BUCKET,
Prefix: dir, Prefix: dir,
MaxKeys: 1000,
}) })
.promise(); .promise();
@@ -114,7 +107,7 @@ export default class S3Storage implements StorageBase {
try { try {
res.status(error.statusCode || 500); res.status(error.statusCode || 500);
} catch (err) { } catch (err) {
console.error(err); console.error(`[ERROR] S3 send ${p}`, err);
} }
}) })
.on("httpHeaders", (statusCode, headers, response) => { .on("httpHeaders", (statusCode, headers, response) => {
@@ -170,6 +163,7 @@ export default class S3Storage implements StorageBase {
.listObjectsV2({ .listObjectsV2({
Bucket: config.S3_BUCKET, Bucket: config.S3_BUCKET,
Prefix: dir, Prefix: dir,
MaxKeys: 1000,
}) })
.promise(); .promise();