Return JSON on unhandled contact errors
This commit is contained in:
parent
74c4acc8e6
commit
481c6a1627
1 changed files with 15 additions and 3 deletions
|
|
@ -149,8 +149,20 @@ const handlePost: PagesFunction<Env> = async ({ request, env }) => {
|
|||
};
|
||||
|
||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
||||
try {
|
||||
if (context.request.method !== "POST") {
|
||||
return jsonResponse({ ok: false, error: "Method not allowed." }, 405);
|
||||
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,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue