Fix consent API: handle empty/invalid JSON body gracefully

This commit is contained in:
Kunthawat
2026-04-01 14:52:20 +07:00
parent a5b882e212
commit 07cdc0dce3

View File

@@ -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(),