2.8 KiB
Debug Network Error in Chat Assistant
Issue
Frontend shows "Network error. Please check your connection." but backend logs show 200 OK.
Root Cause Analysis
The backend is successfully processing requests (200 OK), but the frontend axios client is reporting a network error. This typically means:
- CORS Issue: Response is blocked by browser CORS policy
- Response Format: Response doesn't match expected format
- Timeout: Request takes too long (>30s)
- Network Path: Browser can't reach the backend URL
Debugging Steps
1. Check Browser Console
Open browser DevTools (F12) and check:
- Console tab for error messages
- Network tab to see the actual request/response
- Look for CORS errors (red text)
2. Check API URL
The frontend should use:
- Local development:
http://localhost:4402 - Docker: Should still use
http://localhost:4402(browser makes request from host)
3. Test API Directly
# Test from your machine (not Docker)
curl -X POST http://localhost:4402/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello"}'
4. Check CORS Headers
The backend should return CORS headers. Check in browser Network tab:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: *Access-Control-Allow-Headers: *
5. Check Response Format
The backend returns:
{
"message": "AI response text",
"model": "gemma3:270M",
"tokens_used": 150
}
The frontend expects this format in ChatResponse.
Quick Fixes
Fix 1: Verify API URL
Check what URL the frontend is using:
- Open browser console
- Look for:
API Client initialized with baseURL: ... - Should be:
http://localhost:4402
Fix 2: Check CORS
Backend has allow_origins=["*"] which should work, but verify:
- Check browser Network tab
- Look for OPTIONS preflight request
- Should return 200 OK
Fix 3: Test with curl
curl -v -X POST http://localhost:4402/api/v1/chat \
-H "Content-Type: application/json" \
-H "Origin: http://localhost:8081" \
-d '{"message": "test"}'
Fix 4: Check Response Time
The backend log shows 6.3 seconds. If axios timeout is shorter, it will fail. Current timeout is 30s, so should be fine.
Expected Behavior
- Browser makes POST to
http://localhost:4402/api/v1/chat - Backend processes request (6-7 seconds for Ollama)
- Backend returns 200 OK with JSON response
- Frontend receives response and displays it
Current Status
✅ Backend: Working (200 OK) ❌ Frontend: Network error 🔍 Need to check: Browser console, Network tab, CORS headers
Next Steps
- Open browser DevTools
- Go to Network tab
- Make a chat request
- Check the request details:
- URL
- Status code
- Response headers
- Response body
- Check Console tab for errors