Appearance
AI Troubleshooting Guide ​
Common AI Issues ​
1. Authentication Errors ​
Problem: "Invalid authentication" or 401 errors ​
Symptoms:
- AI analysis fails with 401 status
- "Invalid authentication" error message
- Edge Function returns 401
Solutions:
Check user login status:
javascript// In browser console console.log('Session:', session); console.log('Access token:', session?.access_token);Verify JWT token:
- Ensure user is logged in
- Check if token has expired
- Try logging out and back in
Check Edge Function authentication:
bash# Check Edge Function logs supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo
Prevention:
- Implement token refresh logic
- Add session validation before AI calls
- Monitor token expiration
2. Rate Limiting ​
Problem: "Service is currently overloaded. Please try again in 10 minutes." ​
Symptoms:
- 429 status code from Mistral API
- "Service tier capacity exceeded" error
- AI analysis fails with rate limit message
Solutions:
Wait and retry:
- Wait 10 minutes before retrying
- Implement exponential backoff
- Show user-friendly message
Switch models:
typescript// In Edge Function const model = 'mistral-small-latest'; // Instead of mistral-large-latestOptimize prompts:
- Reduce max_tokens
- Simplify prompt structure
- Use more concise instructions
Prevention:
- Monitor API usage
- Implement request queuing
- Consider upgrading Mistral plan
3. JSON Parsing Errors ​
Problem: "Failed to parse AI analysis" ​
Symptoms:
- JSON.parse() errors in Edge Function
- Malformed JSON from Mistral API
- Truncated or incomplete responses
Solutions:
Check Edge Function logs:
bashsupabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeoVerify Mistral API response:
- Check if response is complete
- Look for truncation issues
- Verify JSON structure
Use error recovery:
- The system automatically attempts recovery
- Falls back to minimal valid response
- Logs detailed error information
Prevention:
- Optimize prompts for consistency
- Reduce max_tokens to avoid truncation
- Implement robust error handling
4. Field Population Issues ​
Problem: Fields not populated correctly ​
Symptoms:
- Some form fields remain empty
- Category not selected
- Structured descriptions not populated
- Price not showing
Solutions:
Check AI response mapping:
javascript// In browser console console.log('AI Data received:', aiData); console.log('Mapped data:', mappedData);Verify field mapping:
- Check
N8NAIProjectAnalyzer.tsxmapping - Verify
CreateListingContent.tsxhandling - Ensure correct field names
- Check
Check category normalization:
- Verify category slugs from database
- Check normalization logic
- Ensure valid category selection
Prevention:
- Test with various project types
- Validate all field mappings
- Add comprehensive logging
5. Network and Timeout Issues ​
Problem: Request timeouts or network errors ​
Symptoms:
- "Failed to fetch" errors
- Request timeouts
- Network connectivity issues
Solutions:
Check network connectivity:
- Verify internet connection
- Test with different URLs
- Check firewall settings
Increase timeout:
typescript// In Edge Function const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 120000); // 2 minutesImplement retry logic:
- Add retry mechanism
- Exponential backoff
- User notification
Prevention:
- Set appropriate timeouts
- Implement retry logic
- Monitor network performance
Debugging Steps ​
1. Check Frontend Logs ​
javascript
// Open browser console and check:
console.log('Session:', session);
console.log('AI Data:', aiData);
console.log('Form Data:', formData);2. Check Edge Function Logs ​
bash
# Check recent logs
supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo
# Check specific time range
supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo --since 1h3. Test Edge Function Directly ​
bash
# Test with curl
curl -X POST https://nujcbrbtejvhuajfwgeo.supabase.co/functions/v1/analyze-project \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
-d '{"url":"https://example.com"}'4. Check Supabase Secrets ​
bash
# List all secrets
supabase secrets list --project-ref nujcbrbtejvhuajfwgeo
# Check specific secret
supabase secrets get MISTRAL_API_KEY --project-ref nujcbrbtejvhuajfwgeoMonitoring and Alerts ​
1. Set Up Monitoring ​
- Monitor Edge Function execution times
- Track API success/failure rates
- Monitor Mistral API usage and costs
2. Implement Alerts ​
- Alert on high error rates
- Monitor rate limit usage
- Track unusual response patterns
3. Log Analysis ​
- Regular log review
- Error pattern identification
- Performance trend analysis
Best Practices ​
1. Error Handling ​
- Always implement try-catch blocks
- Provide user-friendly error messages
- Log detailed error information
- Implement graceful degradation
2. Performance ​
- Optimize prompts for token efficiency
- Implement caching where appropriate
- Monitor response times
- Set appropriate timeouts
3. Security ​
- Never expose API keys in frontend
- Use Supabase secrets for sensitive data
- Implement proper authentication
- Monitor for suspicious activity
Getting Help ​
1. Check Documentation ​
2. Review Logs ​
- Check Edge Function logs
- Review browser console
- Analyze error patterns
3. Test Scenarios ​
- Test with different project types
- Verify with various URLs
- Check edge cases
4. Contact Support ​
- Provide detailed error logs
- Include reproduction steps
- Share relevant configuration