diff --git a/functions/api/contact.ts b/functions/api/contact.ts index ee6a731..c8a1faa 100644 --- a/functions/api/contact.ts +++ b/functions/api/contact.ts @@ -149,8 +149,20 @@ const handlePost: PagesFunction = async ({ request, env }) => { }; export const onRequest: PagesFunction = async (context) => { - if (context.request.method !== "POST") { - return jsonResponse({ ok: false, error: "Method not allowed." }, 405); + try { + if (context.request.method !== "POST") { + return jsonResponse( + { ok: false, error: "Method not allowed." }, + 405, + ); + } + return handlePost(context); + } catch (error) { + const message = + error instanceof Error ? error.message : "Unknown error"; + return jsonResponse( + { ok: false, error: "Unhandled exception.", details: message }, + 500, + ); } - return handlePost(context); };