From 3f575a0e4c9172dd60e79c5e838ab0d27d425238 Mon Sep 17 00:00:00 2001 From: vato007 Date: Tue, 4 Feb 2025 16:48:33 +1030 Subject: [PATCH] Stop waiting for email to send when handling contact form submission --- functions/contact.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/functions/contact.ts b/functions/contact.ts index 6d8114b..ada5ffa 100644 --- a/functions/contact.ts +++ b/functions/contact.ts @@ -28,17 +28,17 @@ export const onRequest: PagesFunction = (context) => { // Must have some kind of identifiable information for me to actually care about them. if ((fullName || email) && message) { - try { - await context.env.SERVICE.sendEmail({ - fullName, - organisation, - email, - mobile, - message, - }); - } catch (e) { - return new Response(e); - } + // Don't await response so the client doesn't have to wait for email to send as it + // feels unresponsive + context.env.SERVICE.sendEmail({ + fullName, + organisation, + email, + mobile, + message, + }) + .then(() => console.log("Sent email")) + .catch((err) => console.error(err)); } return Response.redirect("https://michaelpivato.dev");