diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-06-19 21:02:01 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-19 21:02:01 +0800 |
commit | 89c414326a195d71d1f993af661f94798101e065 (patch) | |
tree | b043de8b7b3e5a9dfdf840bf456c9336fbc42cde /deno/mail-relay/aws/fetch.ts | |
parent | 9abee12c8429141c80cf4ab9e428d3e361fc9bb3 (diff) | |
download | crupest-89c414326a195d71d1f993af661f94798101e065.tar.gz crupest-89c414326a195d71d1f993af661f94798101e065.tar.bz2 crupest-89c414326a195d71d1f993af661f94798101e065.zip |
mail: gracefully handle s3 key not exist.mail
Diffstat (limited to 'deno/mail-relay/aws/fetch.ts')
-rw-r--r-- | deno/mail-relay/aws/fetch.ts | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/deno/mail-relay/aws/fetch.ts b/deno/mail-relay/aws/fetch.ts index c603a35..da8609f 100644 --- a/deno/mail-relay/aws/fetch.ts +++ b/deno/mail-relay/aws/fetch.ts @@ -3,6 +3,7 @@ import { DeleteObjectCommand, GetObjectCommand, ListObjectsV2Command, + NoSuchBucket, S3Client, S3ClientConfig, } from "@aws-sdk/client-s3"; @@ -86,13 +87,22 @@ export class AwsMailFetcher { Bucket: this.#bucket, Key: mailPath, }); - const res = await this.#s3.send(command); - if (res.Body == null) { - throw new Error("S3 API returns a null body."); - } + let rawMail; - const rawMail = await res.Body.transformToString(); + try { + const res = await this.#s3.send(command); + if (res.Body == null) { + throw new Error("S3 API returns a null body."); + } + rawMail = await res.Body.transformToString(); + } catch (cause) { + if (cause instanceof NoSuchBucket) { + console.error(`S3 mail key ${s3Key} not found. Perhaps already consumed?`) + return; + } + throw cause; + } console.info(logTag, `Calling consumer...`); await consumer(rawMail, s3Key); |