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:
@@ -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')
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +260,8 @@ export class TradingViewCapture {
|
||||
|
||||
if (!loggedInCheck) {
|
||||
console.log('Not properly logged in, re-authenticating...')
|
||||
// Reset login state and force re-authentication
|
||||
this.loggedIn = false
|
||||
await this.login()
|
||||
|
||||
// Try navigating to the layout URL again
|
||||
@@ -283,6 +285,15 @@ export class TradingViewCapture {
|
||||
}
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 60000 })
|
||||
}
|
||||
} else {
|
||||
console.log('User menu found but still getting restriction - layout may be private')
|
||||
// Even though we're logged in, the layout is restricted, use base chart
|
||||
console.log(`Layout "${layout}" is private or not accessible, falling back to base chart`)
|
||||
let baseUrl = `https://www.tradingview.com/chart/?symbol=${finalSymbol}`
|
||||
if (finalTimeframe) {
|
||||
baseUrl += `&interval=${encodeURIComponent(finalTimeframe)}`
|
||||
}
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 60000 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user