mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-04 20:57:56 +02:00
feat: improve the error handling in s3
This commit is contained in:
+4
-10
@@ -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();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user