mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 17:26:17 +00:00
feat: Add error handling for navigation interruptions and HTTP 400 responses in login flow
This commit is contained in:
@@ -105,13 +105,51 @@ export class Login {
|
||||
const isLinux = process.platform === 'linux'
|
||||
const navigationTimeout = isLinux ? 60000 : 30000
|
||||
|
||||
// Navigate to dashboard
|
||||
// Try initial navigation with error handling for chrome-error interruption
|
||||
let navigationSucceeded = false
|
||||
try {
|
||||
await page.goto('https://www.bing.com/rewards/dashboard', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: navigationTimeout
|
||||
})
|
||||
navigationSucceeded = true
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : String(error)
|
||||
|
||||
// PATCH: Check for HTTP 400 error and auto-reload (Linux first-load issue)
|
||||
// If interrupted by chrome-error, retry with reload approach
|
||||
if (errorMsg.includes('chrome-error://chromewebdata/')) {
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Navigation interrupted by chrome-error, attempting recovery...', 'warn')
|
||||
|
||||
// Wait a bit for page to settle
|
||||
await this.bot.utils.wait(1000)
|
||||
|
||||
// Try reload which usually fixes the issue
|
||||
try {
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Recovery successful via reload')
|
||||
} catch (reloadError) {
|
||||
// Last resort: try goto again
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Reload failed, trying fresh navigation...', 'warn')
|
||||
await this.bot.utils.wait(1500)
|
||||
await page.goto('https://www.bing.com/rewards/dashboard', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: navigationTimeout
|
||||
})
|
||||
navigationSucceeded = true
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Recovery successful via fresh navigation')
|
||||
}
|
||||
} else {
|
||||
// Different error, rethrow
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
if (!navigationSucceeded) {
|
||||
throw new Error('Failed to navigate to dashboard after multiple attempts')
|
||||
}
|
||||
|
||||
// Additional check for HTTP 400 in page content
|
||||
await this.bot.utils.wait(500)
|
||||
const content = await page.content().catch(() => '')
|
||||
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||
@@ -119,7 +157,7 @@ export class Login {
|
||||
content.includes('Cette page ne fonctionne pas')
|
||||
|
||||
if (hasHttp400) {
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 detected on first load, reloading page...', 'warn')
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 detected in content, reloading...', 'warn')
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
await this.bot.utils.wait(1000)
|
||||
}
|
||||
@@ -175,9 +213,37 @@ export class Login {
|
||||
const isLinux = process.platform === 'linux'
|
||||
const navigationTimeout = isLinux ? 60000 : 30000
|
||||
|
||||
// Try initial navigation with error handling
|
||||
let navigationSucceeded = false
|
||||
try {
|
||||
await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : String(error)
|
||||
|
||||
// PATCH: Check for HTTP 400 and auto-reload
|
||||
if (errorMsg.includes('chrome-error://chromewebdata/')) {
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'OAuth navigation interrupted, attempting recovery...', 'warn')
|
||||
await this.bot.utils.wait(1000)
|
||||
|
||||
try {
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'OAuth recovery successful')
|
||||
} catch (reloadError) {
|
||||
await this.bot.utils.wait(1500)
|
||||
await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
if (!navigationSucceeded) {
|
||||
throw new Error('Failed to navigate to OAuth page')
|
||||
}
|
||||
|
||||
// Check for HTTP 400
|
||||
await this.bot.utils.wait(500)
|
||||
const content = await page.content().catch(() => '')
|
||||
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||
@@ -185,7 +251,7 @@ export class Login {
|
||||
content.includes('Cette page ne fonctionne pas')
|
||||
|
||||
if (hasHttp400) {
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'HTTP 400 detected on OAuth page, reloading...', 'warn')
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'HTTP 400 detected, reloading...', 'warn')
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
await this.bot.utils.wait(1000)
|
||||
}
|
||||
@@ -283,10 +349,36 @@ export class Login {
|
||||
const isLinux = process.platform === 'linux'
|
||||
const navigationTimeout = isLinux ? 60000 : 30000
|
||||
|
||||
// Try navigation with error recovery
|
||||
let navigationSucceeded = false
|
||||
try {
|
||||
await page.goto(homeUrl, { timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : String(error)
|
||||
|
||||
if (errorMsg.includes('chrome-error://chromewebdata/')) {
|
||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Session check interrupted, recovering...', 'warn')
|
||||
await this.bot.utils.wait(1000)
|
||||
|
||||
try {
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
} catch (reloadError) {
|
||||
await this.bot.utils.wait(1500)
|
||||
await page.goto(homeUrl, { timeout: navigationTimeout })
|
||||
navigationSucceeded = true
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
if (!navigationSucceeded) return false
|
||||
|
||||
await page.waitForLoadState('domcontentloaded').catch(logError('LOGIN', 'DOMContentLoaded timeout', this.bot.isMobile))
|
||||
|
||||
// PATCH: Check for HTTP 400 and auto-reload
|
||||
// Check for HTTP 400
|
||||
await this.bot.utils.wait(500)
|
||||
const content = await page.content().catch(() => '')
|
||||
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||
|
||||
Reference in New Issue
Block a user