From 630387f8896f028f5844104af8a3a86cc4edf1ca Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 15 Dec 2024 00:00:32 -0800 Subject: [PATCH] better logging --- src/api.ts | 24 ++++++++++++++++++------ src/email.ts | 4 +++- src/job.ts | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/api.ts b/src/api.ts index d8a3008..cfb446a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -17,18 +17,30 @@ export const main = (port: number) => { jobInsensitive.to.username = "****REDACTED****"; jobInsensitive.to.password = "****REDACTED****"; + const uuid = crypto.randomUUID(); ConsoleLogger.log( - `Received email job: ${JSON.stringify(jobInsensitive)}`, + `[${uuid}] Received email job: ${JSON.stringify(jobInsensitive)}`, )(); const performEmailTest = perform(job)(); - return await performEmailTest - .then(() => { + return performEmailTest + .then((result) => { + if (result._tag === "Left") { + const error = result.left; + ConsoleLogger.log( + `[${uuid}] job failure due to ${error.message}`, + )(); + return new Response(error.message, { + status: 400, + }); + } + ConsoleLogger.log(`[${uuid}] success`)(); return Response.json({ success: true }); }) - .catch((error) => { - return new Response(error.message, { - status: 400, + .catch((e) => { + ConsoleLogger.log(`[${uuid}] internal failure due to ${e}`)(); + return new Response(e.message, { + status: 500, }); }); } diff --git a/src/email.ts b/src/email.ts index a017aac..f916022 100644 --- a/src/email.ts +++ b/src/email.ts @@ -192,7 +192,9 @@ const findEmailUidInInbox: FindEmailUidInInbox = ( TE.fold( (e) => pipe( - TE.fromIO(ConsoleLogger.log(`failed; ${retries} retries left.`)), + TE.fromIO( + ConsoleLogger.log(`failed to find email; ${retries} retries left.`), + ), TE.chain(() => retries === 0 ? TE.left(e) diff --git a/src/job.ts b/src/job.ts index 2beabca..dbd2605 100644 --- a/src/job.ts +++ b/src/job.ts @@ -14,6 +14,7 @@ export interface EmailToInstruction extends EmailInstruction { } export interface EmailJob { + requestId: string; from: EmailFromInstruction; to: EmailToInstruction; readRetry: Retry;