From 20df952aa5bacba207fa92eec78397226d4ed4b0 Mon Sep 17 00:00:00 2001 From: Calum Muir Date: Sun, 28 Dec 2025 12:33:28 +0000 Subject: [PATCH] Return Turnstile verification details --- functions/api/contact.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/functions/api/contact.ts b/functions/api/contact.ts index bd6e5f7..ee6a731 100644 --- a/functions/api/contact.ts +++ b/functions/api/contact.ts @@ -57,11 +57,33 @@ const handlePost: PagesFunction = async ({ request, env }) => { ); const verifyResult = (await verifyResponse.json()) as { success?: boolean; + "error-codes"?: string[]; + messages?: string[]; + hostname?: string; + action?: string; + cdata?: string; }; if (!verifyResult.success) { + const details = [ + verifyResult["error-codes"]?.length + ? `codes=${verifyResult["error-codes"].join(",")}` + : "", + verifyResult.messages?.length + ? `messages=${verifyResult.messages.join(",")}` + : "", + verifyResult.hostname ? `hostname=${verifyResult.hostname}` : "", + verifyResult.action ? `action=${verifyResult.action}` : "", + ] + .filter(Boolean) + .join(" | ") + .slice(0, 500); return jsonResponse( - { ok: false, error: "Turnstile verification failed." }, + { + ok: false, + error: "Turnstile verification failed.", + details: details || undefined, + }, 400, ); }