Skip to content

Commit

Permalink
chore: Improve email failure logging (#4209)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jan 25, 2025
1 parent 5607aff commit a7eff12
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions api.planx.uk/modules/sendEmail/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const singleApplicationEmailController: SingleApplicationEmail = async (
});
return res.json(response);
} catch (error) {
emailErrorHandler(next, error, template);
emailErrorHandler(next, error, template, sessionId);
}
};

Expand All @@ -42,7 +42,12 @@ export const paymentEmailController: PaymentEmail = async (_req, res, next) => {
});
return res.json(response);
} catch (error) {
emailErrorHandler(next, error, template);
emailErrorHandler(
next,
error,
template,
`(payment request) ${paymentRequestId}`,
);
}
};

Expand All @@ -69,19 +74,20 @@ export const confirmationEmailController: ConfirmationEmail = async (
return res.json(response);
}
} catch (error) {
emailErrorHandler(next, error, template);
emailErrorHandler(next, error, template, sessionId);
}
};

const emailErrorHandler = (
next: NextFunction,
error: unknown,
template: string,
sessionId: string,
) =>
next(
new ServerError({
status: error instanceof ServerError ? error.status : undefined,
message: `Failed to send "${template}" email. ${
message: `Failed to send "${template}" email for session ${sessionId}. ${
(error as Error).message
}`,
}),
Expand Down

0 comments on commit a7eff12

Please sign in to comment.