diff options
-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); |