From 07cdc0dce359f90a8c27a3b7fb4af75efeb5b0fb Mon Sep 17 00:00:00 2001 From: Kunthawat Date: Wed, 1 Apr 2026 14:52:20 +0700 Subject: [PATCH] Fix consent API: handle empty/invalid JSON body gracefully --- src/pages/api/consent/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/api/consent/index.ts b/src/pages/api/consent/index.ts index 78b6d25..376aa6b 100644 --- a/src/pages/api/consent/index.ts +++ b/src/pages/api/consent/index.ts @@ -1,7 +1,16 @@ import type { APIRoute } from 'astro'; export const POST: APIRoute = async ({ request }) => { - const consentData = await request.json(); + let consentData = {}; + + try { + const text = await request.text(); + if (text) { + consentData = JSON.parse(text); + } + } catch (e) { + console.error('[Consent API] JSON parse error:', e); + } const record = { id: crypto.randomUUID(),