fix(myTischtennis): improve error detection during login process

- Introduced enhanced error detection for CAPTCHA and login failures by probing page text during cookie retrieval attempts.
- Reduced maximum polling attempts and adjusted polling interval for better performance and responsiveness.
- Updated error handling to provide clearer feedback on specific login issues encountered during the authentication process.
This commit is contained in:
Torsten Schulz (local)
2026-03-02 11:40:49 +01:00
parent 6ab6319256
commit d33e9a94cf

View File

@@ -547,7 +547,9 @@ class MyTischtennisClient {
// Wait for auth cookie after submit (polling avoids timing races).
let authCookieObj = null;
const maxAttempts = 80;
let detectedSubmitError = null;
const pollIntervalMs = 500;
const maxAttempts = 40; // ~20s max wait after submit
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const cookies = await context.cookies();
authCookieObj = cookies.find((c) => c.name === 'sb-10-auth-token')
@@ -557,7 +559,29 @@ class MyTischtennisClient {
console.log('[myTischtennisClient.playwright] Auth cookie detected:', authCookieObj.name);
break;
}
await page.waitForTimeout(500);
// Probe page text periodically to fail fast instead of waiting full timeout.
if (attempt % 4 === 0) {
try {
const textContent = await page.locator('body').innerText({ timeout: 600 });
if (textContent?.includes('Captcha-Bestätigung fehlgeschlagen')) {
detectedSubmitError = 'Captcha-Bestätigung fehlgeschlagen';
break;
}
if (textContent?.includes('Captcha-Bestätigung ist erforderlich')) {
detectedSubmitError = 'Captcha-Bestätigung ist erforderlich';
break;
}
if (textContent?.includes('Ungültige E-Mail oder Passwort')) {
detectedSubmitError = 'Ungültige E-Mail oder Passwort';
break;
}
} catch (_readBodyErr) {
// ignore text read errors during polling
}
}
await page.waitForTimeout(pollIntervalMs);
}
if (!authCookieObj || !authCookieObj.value) {
let errorText = null;
@@ -572,6 +596,9 @@ class MyTischtennisClient {
} catch (_e) {
// ignore text read errors
}
if (!errorText && detectedSubmitError) {
errorText = detectedSubmitError;
}
return {
success: false,
error: errorText