summaryrefslogtreecommitdiff
path: root/src/api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api.ts')
-rw-r--r--src/api.ts24
1 files changed, 18 insertions, 6 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,
});
});
}