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 | 888650202daeed5c5b423013df9a629d36c3d007 (patch) | |
| tree | 6af7c7e5a1d7eacf6737ea613690c1fb0eb7defd /deno/mail-relay/aws | |
| parent | fd8ccbae956dd6cdba8d8a34692f65ad3663d7ac (diff) | |
| download | crupest-888650202daeed5c5b423013df9a629d36c3d007.tar.gz crupest-888650202daeed5c5b423013df9a629d36c3d007.tar.bz2 crupest-888650202daeed5c5b423013df9a629d36c3d007.zip  | |
mail: gracefully handle s3 key not exist.
Diffstat (limited to 'deno/mail-relay/aws')
| -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);  | 
