Add logging to track post creation and API fallback

Add detailed console logs to the `createPost` function to trace API calls, successful responses, errors, and fallback to direct Supabase inserts, skipping Discord synchronization.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: feb37d47-5b11-4872-820a-7df0da43eae9
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/duiWnI1
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sirpiglr 2025-12-03 03:52:19 +00:00
commit 51f7fd0d59
2 changed files with 9 additions and 3 deletions

View file

@ -61,7 +61,7 @@ localPort = 40437
externalPort = 3001
[[ports]]
localPort = 43741
localPort = 41051
externalPort = 3002
[deployment]

View file

@ -400,23 +400,29 @@ export const communityService = {
"id" | "created_at" | "updated_at" | "likes_count" | "comments_count"
>,
): Promise<CommunityPost> {
console.log("[createPost] Starting - calling API at", `${API_BASE}/api/posts`);
try {
const resp = await fetch(`${API_BASE}/api/posts`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(post),
});
console.log("[createPost] API response status:", resp.status);
if (resp.ok) {
return (await resp.json()) as CommunityPost;
const result = await resp.json();
console.log("[createPost] API success - post created via API (Discord sync enabled)");
return result as CommunityPost;
}
if (resp.status >= 400) {
const payload = await resp.json().catch(() => ({}));
console.error("[createPost] API error:", payload);
throw new Error(payload?.error || `API responded with ${resp.status}`);
}
} catch (error) {
console.warn("Falling back to Supabase insert for post:", error);
console.warn("[createPost] API failed, falling back to direct Supabase (NO Discord sync):", error);
}
console.log("[createPost] Using direct Supabase insert (Discord sync SKIPPED)");
const { data, error } = await supabase
.from("community_posts")
.insert(post)