From 39a1394ecc310f6487a9c18fe028b32297ac759c Mon Sep 17 00:00:00 2001 From: e Date: Sun, 21 Jul 2024 14:54:53 +0200 Subject: [PATCH] enhance err mssg --- server/server.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/server.tsx b/server/server.tsx index 3930e9a..9b0c838 100644 --- a/server/server.tsx +++ b/server/server.tsx @@ -8,12 +8,19 @@ import { EirikLd } from '../src/ld'; import { ContactFormData } from '../src/types'; import { Resend } from 'resend'; +const missingEnvVars:Array = []; +for (const envVar of ['RESEND_API_KEY','RESEND_TO_EMAIL','RESEND_FROM_EMAIL']){ + if (!process.env[envVar]){ + missingEnvVars.push(envVar); + } +} +if (missingEnvVars.length){ + throw new Error(`Missing env vars [ ${missingEnvVars.join(', ')} ]`); +} + const resend = new Resend(process.env['RESEND_API_KEY']); const toMail = process.env['RESEND_TO_EMAIL']; const fromMail = process.env['RESEND_FROM_EMAIL']; -if (!toMail||!fromMail){ - throw new Error("Incomplete mail config"); -} const PORT = process.env.PORT || 3000; const app = express();