From d33e9a94cf19c07159b3410d9794d18dce4d6e01 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 2 Mar 2026 11:40:49 +0100 Subject: [PATCH] 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. --- backend/clients/myTischtennisClient.js | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/backend/clients/myTischtennisClient.js b/backend/clients/myTischtennisClient.js index 509d51d5..96d75421 100644 --- a/backend/clients/myTischtennisClient.js +++ b/backend/clients/myTischtennisClient.js @@ -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