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:
@@ -26,14 +26,27 @@ function decryptData(data) {
|
||||
if (!data || data === null || data === undefined || data === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Prüfe, ob die Daten bereits entschlüsselt sind (nicht im Hex-Format)
|
||||
// Hex-Strings haben nur 0-9 und a-f Zeichen und gerade Länge
|
||||
const isHexString = /^[0-9a-fA-F]+$/.test(data) && data.length % 2 === 0;
|
||||
|
||||
if (!isHexString) {
|
||||
// Daten sind wahrscheinlich bereits entschlüsselt oder in einem anderen Format
|
||||
// Versuche, sie direkt zurückzugeben
|
||||
return data;
|
||||
}
|
||||
|
||||
try {
|
||||
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), Buffer.alloc(16, 0));
|
||||
let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
console.error('[decryptData] Error decrypting data:', error);
|
||||
return null;
|
||||
// Wenn Entschlüsselung fehlschlägt, versuche die Daten direkt zurückzugeben
|
||||
// (falls sie bereits entschlüsselt sind)
|
||||
console.warn('[decryptData] Error decrypting data, returning as-is:', error.message);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user