Fix login restriction handling and improve AI analysis debugging

- Add proper handling when layouts are private/restricted even with login
- Force re-authentication when restriction is detected without user menu
- Fall back to base chart when layouts are inaccessible
- Add detailed logging to AI analysis service to debug JSON parsing issues
- Log full AI response content and extracted JSON for troubleshooting

This should fix both the login restriction bypass and AI analysis failures.
This commit is contained in:
root
2025-07-09 15:05:42 +02:00
parent 61fae23ea2
commit be2699d489
2 changed files with 17 additions and 0 deletions

View File

@@ -184,16 +184,22 @@ Be concise but thorough. Only return valid JSON.`
throw new Error('No content received from OpenAI')
}
console.log('AI response content:', content)
// Parse the JSON response
const jsonMatch = content.match(/\{[\s\S]*\}/)
if (!jsonMatch) {
console.error('No JSON found in response. Full content:', content)
throw new Error('No JSON found in response')
}
console.log('Extracted JSON:', jsonMatch[0])
const analysis = JSON.parse(jsonMatch[0])
// Validate the structure
if (!analysis.summary || !analysis.marketSentiment || !analysis.recommendation || !analysis.confidence) {
console.error('Invalid analysis structure:', analysis)
throw new Error('Invalid analysis structure')
}