Return JSON on unhandled contact errors

This commit is contained in:
Calum Muir 2025-12-28 12:57:21 +00:00
parent 74c4acc8e6
commit 481c6a1627

View file

@ -149,8 +149,20 @@ const handlePost: PagesFunction<Env> = async ({ request, env }) => {
}; };
export const onRequest: PagesFunction<Env> = async (context) => { export const onRequest: PagesFunction<Env> = async (context) => {
if (context.request.method !== "POST") { try {
return jsonResponse({ ok: false, error: "Method not allowed." }, 405); 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);
}; };