Refactor global error handling in server and improve logging in myTischtennisService

This commit moves the global error handling middleware in server.js to ensure it is applied after all routes. It also enhances the error handling in myTischtennisService by adding detailed logging for login attempts and failures, improving the visibility of issues during the login process. Additionally, the decryptData function in encrypt.js is updated to check if data is already decrypted, enhancing its robustness. Frontend changes include a minor adjustment to the button type in MyTischtennisAccount.vue for better accessibility.
This commit is contained in:
Torsten Schulz (local)
2025-11-21 09:17:48 +01:00
parent 0525f7908d
commit 51e47cf9f9
4 changed files with 67 additions and 43 deletions

View File

@@ -182,6 +182,10 @@ class MyTischtennisService {
if (!password) {
if (hasStoredPassword) {
password = account.getPassword();
if (!password) {
console.error('[myTischtennisService.verifyLogin] Could not decrypt stored password');
throw new HttpError('Gespeichertes Passwort konnte nicht entschlüsselt werden. Bitte Passwort erneut eingeben.', 400);
}
} else if (hasValidSession) {
// Prüfe, ob bestehende Session noch gültig ist
const profileResult = await myTischtennisClient.getUserProfile(account.cookie);
@@ -214,7 +218,9 @@ class MyTischtennisService {
}
// Login-Versuch mit Passwort
console.log('[myTischtennisService.verifyLogin] Attempting login for user:', account.email);
const loginResult = await myTischtennisClient.login(account.email, password);
console.log('[myTischtennisService.verifyLogin] Login result:', { success: loginResult.success, error: loginResult.error });
if (loginResult.success) {
account.lastLoginSuccess = now;
@@ -248,7 +254,9 @@ class MyTischtennisService {
};
} else {
await account.save(); // Save lastLoginAttempt
throw new HttpError(loginResult.error || 'myTischtennis-Login fehlgeschlagen', 401);
const errorMessage = loginResult.error || 'myTischtennis-Login fehlgeschlagen';
console.error('[myTischtennisService.verifyLogin] Login failed:', errorMessage);
throw new HttpError(errorMessage, 401);
}
}