From 789abd38d57fb45552d1eccb98d048de3d79fc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Galdal?= Date: Mon, 19 Jan 2026 20:05:12 +0100 Subject: [PATCH 1/2] add try around confirmation email/sms --- pages/api/applicants/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pages/api/applicants/index.ts b/pages/api/applicants/index.ts index e1308d3c..1a05d6ba 100644 --- a/pages/api/applicants/index.ts +++ b/pages/api/applicants/index.ts @@ -56,8 +56,16 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const mode = process.env.NODE_ENV; if (applicant && mode == "production") { - await sendConfirmationEmail(applicant); - await sendConfirmationSMS(applicant); + try { + await sendConfirmationEmail(applicant); + } catch (error) { + console.error("Could not send confirmation email", error); + } + try { + await sendConfirmationSMS(applicant); + } catch (error) { + console.error("Could not send confirmation SMS", error); + } } return res.status(201).json({ applicant }); From 7e27310210ee2d660af4191bfc4758dd3688c91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Galdal?= Date: Mon, 19 Jan 2026 20:11:50 +0100 Subject: [PATCH 2/2] add failsafe for other emails --- lib/sendInterviewTimes/formatAndSend.ts | 31 ++++++++++++++++++------- pages/api/applicants/index.ts | 13 +++++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/sendInterviewTimes/formatAndSend.ts b/lib/sendInterviewTimes/formatAndSend.ts index ace1da82..34f0b02c 100644 --- a/lib/sendInterviewTimes/formatAndSend.ts +++ b/lib/sendInterviewTimes/formatAndSend.ts @@ -25,21 +25,34 @@ export const formatAndSendEmails = async ({ // Send email to each applicant applicantsToEmail.forEach( async (applicant: emailApplicantInterviewType) => { - await sendEmail({ - toEmails: [applicant.applicantEmail], - subject: `Hei, ${applicant.applicantName}, her er dine intervjutider:`, - htmlContent: formatApplicantInterviewEmail(applicant), - }); + let potentialError; + + try { + await sendEmail({ + toEmails: [applicant.applicantEmail], + subject: `Hei, ${applicant.applicantName}, her er dine intervjutider:`, + htmlContent: formatApplicantInterviewEmail(applicant), + }); + } catch (error) { + potentialError = error; + } finally { + sendSMS( + `+${applicant.applicantPhone}`, + formatInterviewSMS(applicant), + ); + } - sendSMS(`+${applicant.applicantPhone}`, formatInterviewSMS(applicant)); - } + if (potentialError) { + throw potentialError; + } + }, ); // Send email to each committee committeesToEmail.forEach( async (committee: emailCommitteeInterviewType) => { const subject = `${changeDisplayName( - committee.committeeName + committee.committeeName, )} sine intervjutider for ${committee.period_name}`; await sendEmail({ @@ -47,7 +60,7 @@ export const formatAndSendEmails = async ({ subject: subject, htmlContent: formatCommitteeInterviewEmail(committee), }); - } + }, ); } catch (error) { return { error: "Failed to send out interview times" }; diff --git a/pages/api/applicants/index.ts b/pages/api/applicants/index.ts index 1a05d6ba..ee6440cb 100644 --- a/pages/api/applicants/index.ts +++ b/pages/api/applicants/index.ts @@ -56,15 +56,18 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const mode = process.env.NODE_ENV; if (applicant && mode == "production") { + let potentialError; + try { await sendConfirmationEmail(applicant); } catch (error) { - console.error("Could not send confirmation email", error); - } - try { + potentialError = error; + } finally { await sendConfirmationSMS(applicant); - } catch (error) { - console.error("Could not send confirmation SMS", error); + } + + if (potentialError) { + throw potentialError; } }