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, ); }