ProxySetup Endpoint - Debugging Guide
What I’ve Updated
I’ve enhanced the ProxySetup.svelte component with comprehensive logging and debugging to help identify why the backend request isn’t working correctly.
Changes Made:
-
Enhanced Console Logging - The component now logs:
- Request URL being called
- Full request body
- Response status and headers
- Response body (success and error cases)
- Detailed error messages with colored console output (🔵, 🟢, 🔴)
-
Debug Info Display - The ProxySetup screen now shows:
- The
VITE_API_BASEvalue currently being used - The full URL being constructed for the request
- The
-
Better Error Handling:
- Detects response content-type and parses accordingly
- Shows user-friendly error messages
- Validates that response is JSON before parsing
-
Session Code Validation - Shows error if session code is missing
How to Debug
Step 1: Check Console Logs
When the ProxySetup screen appears:
- Open browser DevTools (F12)
- Go to “Console” tab
- The component will show:
Debug Infobox with the API base URL and full endpoint URL being used- Expected URLs:
http://localhost:8000/session/ABC123/proxy(adjust port/domain as needed)
Step 2: Click Continue and Watch Logs
When you select a senator option and click “Continue”:
- Look for 🔵 (blue circle) logs showing the request being sent
- Watch for response logs:
- If you see 🟢 (green circle): Request succeeded! Check that the notice message appears
- If you see 🔴 (red circle): Request failed. Error message will be displayed
Step 3: Common Issues and Solutions
Issue: “HTTP 401 Unauthorized”
Causes:
- User is not authenticated with the auth service
- Auth cookie is not being sent with request
- Auth service session expired
Solutions:
- Make sure you’re logged in via SignIn screen first
- Check if auth service cookie is set (look in DevTools > Application > Cookies)
- Try clearing cookies and re-authenticating
Issue: “HTTP 404 Not Found”
Causes:
- API base URL is wrong
- Endpoint path is incorrect
- Backend isn’t running
Solutions:
- Check the Debug Info box on the screen - verify the URL matches your backend
- Make sure
VITE_API_BASEenvironment variable is set correctly (e.g.,http://localhost:8000) - Verify backend is running on the expected port:
cargo run --bin backend
Issue: “HTTP 500 Internal Server Error”
Causes:
- Backend crashed or database error
- Session code doesn’t exist
- Database not initialized
Solutions:
- Check backend console for error messages
- Verify database migrations have run
- Try a known valid session code
Issue: “Expected JSON response, got text/html”
Causes:
- Request is hitting a different endpoint (maybe a 404 page)
- CORS issue preventing proper response
Solutions:
- Verify the API base URL in Debug Info is correct
- Check backend CORS configuration is allowing the request
- Look at “Network” tab in DevTools to see actual response
Issue: “Error: Timeout” or no response at all
Causes:
- Backend not running
- Network connectivity issue
- API base URL unreachable
Solutions:
- Start backend:
cd backend && cargo run --bin backend - Verify API base URL is accessible (try pinging it, or open in browser)
- Check firewall/network settings
Step 4: Network Tab Inspection
For more detailed information:
- Open DevTools
- Go to “Network” tab
- Click “Continue” button
- Look for the
proxyrequest - Click on it to see:
- Headers: Shows request headers (Content-Type, credentials)
- Request: Shows the JSON body being sent
- Response: Shows the server’s response
- Timing: Shows how long the request took
Step 5: Backend Logs
If the console logs show the request was sent but you can’t see what the backend is doing:
- Run backend with verbose logging:
cd /home/yy/repos/voting-app/backendRUST_LOG=debug cargo run --bin backend- Look for logs about:
- Incoming requests
- Database queries
- User authentication
- Session lookups
Expected Behavior When Working
When everything is working correctly:
-
ProxySetup screen appears with:
- The correct session code
- Debug info showing the API URL
- Senator dropdown and optional proxy input
-
You select options and click Continue:
- Senator: Yes/No (required)
- Proxying for: Name (optional)
-
Console shows (in order):
🔵 Sending proxy request: { url: "...", ... }🔵 Response received: { status: 200, statusText: "OK", ... }🟢 Success! Proxy response: { vote_instance_count: 2, is_senator: true, has_proxy: true } -
Success message appears:
- “You now have 2 vote instances (your own vote + one proxy vote).”
- Or appropriate message based on your configuration
-
Moves to WaitingPage with the participation notice displayed
Testing the Endpoint Manually
If you want to test directly without the frontend:
Using curl:
curl -X POST http://localhost:8000/session/ABC123/proxy \ -H "Content-Type: application/json" \ -H "Cookie: <your_auth_cookie>" \ -d '{"is_senator": true, "proxy_for": "Jane Doe"}'Expected Response:
{ "vote_instance_count": 2, "is_senator": true, "has_proxy": true}Using API Client (Postman, REST Client, etc.):
- Method: POST
- URL:
http://localhost:8000/session/{SESSION_CODE}/proxy - Headers:
Content-Type: application/jsonCookie: <auth_session_cookie>
- Body (JSON):
{ "is_senator": true, "proxy_for": "Jane Doe"}Additional Debug Info
Backend Endpoint Details
- Route:
POST /session/{session_code}/proxy - Auth Required: Yes (needs valid session cookie)
- Request Type:
SetSessionProxyRequestis_senator: bool(required)proxy_for: Option<String>(optional, null if not proxying)
- Response Type:
SetSessionProxyResponsevote_instance_count: numberis_senator: booleanhas_proxy: boolean
Frontend Environment Variables
Make sure these are set correctly:
# .env or .env.localVITE_API_BASE=http://localhost:8000# or for production:VITE_API_BASE=https://api.example.comNext Steps After Debugging
Once you identify the issue:
- If it’s an auth issue: Ensure auth service is running and cookies are being set
- If it’s a URL issue: Update
VITE_API_BASEenvironment variable - If it’s a backend issue: Check database, migrations, and server logs
- If everything works: Remove debug info display (optional - it won’t hurt to leave it)
To remove debug info display later, simply delete or comment out the <div class="debug-info"> block in ProxySetup.svelte.
Questions to Answer
When debugging, try to identify:
- ✅ Is the request being sent at all? (Check console logs)
- ✅ What is the response status code? (200, 401, 404, 500, etc.)
- ✅ What is the API base URL being used?
- ✅ Is the user authenticated? (Check cookies)
- ✅ Is the backend running? (Try accessing
/healthendpoint) - ✅ Does the session code exist? (Check database or backend logs)
Good luck debugging!