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
This commit is contained in:
commit
4fa7c9b14a
2 changed files with 15 additions and 9 deletions
4
.replit
4
.replit
|
|
@ -52,10 +52,6 @@ externalPort = 80
|
|||
localPort = 8044
|
||||
externalPort = 3003
|
||||
|
||||
[[ports]]
|
||||
localPort = 35709
|
||||
externalPort = 3002
|
||||
|
||||
[[ports]]
|
||||
localPort = 38557
|
||||
externalPort = 3000
|
||||
|
|
|
|||
|
|
@ -400,21 +400,31 @@ export const communityService = {
|
|||
"id" | "created_at" | "updated_at" | "likes_count" | "comments_count"
|
||||
>,
|
||||
): Promise<CommunityPost> {
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue