diff --git a/src/pages/api/contact.ts b/src/pages/api/contact.ts index dd1381a..8fdf1bf 100644 --- a/src/pages/api/contact.ts +++ b/src/pages/api/contact.ts @@ -302,26 +302,19 @@ export const POST: APIRoute = async ({ request, clientAddress }) => { ); } - // Send email - try { - await sendContactEmail(formData); - } catch { - logApiRequest({ - scope: 'api.contact', - method: 'POST', - path: '/api/contact', - status: 500, - ip, - durationMs: Date.now() - startTime, + // Fire-and-forget: send email in background so the user gets an instant response. + // Errors are logged/reported but never block the HTTP reply. + sendContactEmail(formData).catch(async (err) => { + logger.error('api.contact', 'Background email delivery failed', { + email: formData.email, + subject: formData.subject, + error: err instanceof Error ? err.message : String(err), }); - return new Response( - JSON.stringify({ - success: false, - error: 'Failed to send message. Please try again or email us directly.', - }), - { status: 500, headers: rateLimitHeaders } - ); - } + await captureException(err, { + scope: 'api.contact.background', + extra: { email: formData.email, subject: formData.subject }, + }); + }); logApiRequest({ scope: 'api.contact', @@ -334,7 +327,7 @@ export const POST: APIRoute = async ({ request, clientAddress }) => { return new Response( JSON.stringify({ success: true, - message: "Message sent successfully! We'll get back to you within 24 hours.", + message: "Message received! We'll get back to you within 24 hours.", }), { status: 200, headers: rateLimitHeaders } );