From e1e70713a2445a78aa0ba7f3580d1fdc95e6880a Mon Sep 17 00:00:00 2001 From: sirpiglr <49359077-sirpiglr@users.noreply.replit.com> Date: Wed, 3 Dec 2025 19:09:46 +0000 Subject: [PATCH] Add detailed logging to help troubleshoot post creation failures Implement client-side logging within the `createPost` function to capture API request details, response status, and potential errors, aiding in debugging the "Unexpected end of JSON input" issue. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 269a3c56-a424-46ab-8eea-6f3af8c76051 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/zMxtXds Replit-Helium-Checkpoint-Created: true --- .replit | 4 ---- client/lib/supabase-service.ts | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.replit b/.replit index a32138b6..07348546 100644 --- a/.replit +++ b/.replit @@ -52,10 +52,6 @@ externalPort = 80 localPort = 8044 externalPort = 3003 -[[ports]] -localPort = 35709 -externalPort = 3002 - [[ports]] localPort = 38557 externalPort = 3000 diff --git a/client/lib/supabase-service.ts b/client/lib/supabase-service.ts index d1a6af21..959b2adb 100644 --- a/client/lib/supabase-service.ts +++ b/client/lib/supabase-service.ts @@ -400,21 +400,31 @@ export const communityService = { "id" | "created_at" | "updated_at" | "likes_count" | "comments_count" >, ): Promise { + const apiUrl = `${API_BASE}/api/posts`; + console.log("[createPost] Attempting POST to:", apiUrl); + console.log("[createPost] Payload:", JSON.stringify(post).slice(0, 200)); + try { - const resp = await fetch(`${API_BASE}/api/posts`, { + const resp = await fetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(post), }); + console.log("[createPost] Response status:", resp.status, resp.statusText); + if (resp.ok) { - return (await resp.json()) as CommunityPost; + const json = await resp.json(); + console.log("[createPost] Success:", json?.id); + return json as CommunityPost; } if (resp.status >= 400) { - const payload = await resp.json().catch(() => ({})); + const text = await resp.text(); + console.error("[createPost] API error response:", text.slice(0, 500)); + const payload = text ? JSON.parse(text) : {}; throw new Error(payload?.error || `API responded with ${resp.status}`); } - } catch (error) { - console.warn("Falling back to Supabase insert for post:", error); + } catch (error: any) { + console.error("[createPost] Fetch error:", error?.message || error); } const { data, error } = await supabase