attach the request id during the job
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c0a96e82af
commit
157dc327e8
21
src/api.ts
21
src/api.ts
@ -1,6 +1,6 @@
|
||||
import { perform } from "./email";
|
||||
import { redactJob, type EmailJob } from "./job";
|
||||
import { ConsoleLogger } from "./logger";
|
||||
import { ConsoleLogger, type Logger } from "./logger";
|
||||
|
||||
export const main = (port: number) => {
|
||||
const server = Bun.serve({
|
||||
@ -14,27 +14,32 @@ export const main = (port: number) => {
|
||||
const jobInsensitive = redactJob(job);
|
||||
|
||||
const uuid = crypto.randomUUID();
|
||||
ConsoleLogger.info(
|
||||
`[${uuid}] Received email job: ${JSON.stringify(jobInsensitive)}`,
|
||||
const logger: Logger = {
|
||||
info: (message) => ConsoleLogger.info(`[${uuid}] ${message}`),
|
||||
warn: (message) => ConsoleLogger.warn(`[${uuid}] ${message}`),
|
||||
error: (message) => ConsoleLogger.error(`[${uuid}] ${message}`),
|
||||
}
|
||||
logger.info(
|
||||
`Received email job: ${JSON.stringify(jobInsensitive)}`,
|
||||
)();
|
||||
|
||||
const performEmailTest = perform(job)();
|
||||
const performEmailTest = perform(job, undefined, logger)();
|
||||
return performEmailTest
|
||||
.then((result) => {
|
||||
if (result._tag === "Left") {
|
||||
const error = result.left;
|
||||
ConsoleLogger.warn(
|
||||
`[${uuid}] job failure due to ${error.message}`,
|
||||
logger.warn(
|
||||
`job failure due to ${error.message}`,
|
||||
)();
|
||||
return new Response(error.message, {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
ConsoleLogger.info(`[${uuid}] success`)();
|
||||
logger.info('success')();
|
||||
return Response.json({ success: true });
|
||||
})
|
||||
.catch((e) => {
|
||||
ConsoleLogger.error(`[${uuid}] internal failure due to ${e}`)();
|
||||
logger.error(`internal failure due to ${e}`)();
|
||||
return new Response(e.message, {
|
||||
status: 500,
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ import * as TE from "fp-ts/lib/TaskEither";
|
||||
import * as O from "fp-ts/lib/Option";
|
||||
import { createTransport } from "nodemailer";
|
||||
import { toError } from "fp-ts/lib/Either";
|
||||
import { flow, pipe } from "fp-ts/lib/function";
|
||||
import { pipe } from "fp-ts/lib/function";
|
||||
import {
|
||||
ImapFlow,
|
||||
type FetchMessageObject,
|
||||
|
Loading…
Reference in New Issue
Block a user