From 1df769777ae14676ee013106897c72ce8d03457c Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Mon, 27 Apr 2026 20:44:02 +0500 Subject: [PATCH] Add debug logging to PB requests --- frontend/src/pages/api/increment-views.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/api/increment-views.ts b/frontend/src/pages/api/increment-views.ts index 1ef5253..b2d8e48 100644 --- a/frontend/src/pages/api/increment-views.ts +++ b/frontend/src/pages/api/increment-views.ts @@ -19,18 +19,24 @@ function generateVisitorHash(ip: string, userAgent: string): string { async function pbRequest(method: string, path: string, body?: object) { const url = `${POCKETBASE_URL}${path}`; + console.log('[Increment Views] PB Request:', method, url); const options: RequestInit = { method, headers: { 'Content-Type': 'application/json' }, }; - if (body) options.body = JSON.stringify(body); + if (body) { + options.body = JSON.stringify(body); + console.log('[Increment Views] PB Body:', JSON.stringify(body)); + } const res = await fetch(url, options); + const status = res.status; + const err = await res.text(); + console.log('[Increment Views] PB Response:', status, err); if (!res.ok) { - const err = await res.text(); - throw new Error(`PB ${method} ${path}: ${res.status} - ${err}`); + throw new Error(`PB ${method} ${path}: ${status} - ${err}`); } - return res.json(); + return JSON.parse(err) || {}; } export const POST: APIRoute = async ({ request, url }) => {