aktueller stand
This commit is contained in:
10
server.js
10
server.js
@@ -774,6 +774,16 @@ async function restoreSessionsFromDisk() {
|
||||
console.log(`[RESTORE] Session fuer Profil ${profile.id} (${profile.name}) reaktiviert.`);
|
||||
} catch (error) {
|
||||
console.error(`[RESTORE] Login fuer Profil ${profileId} fehlgeschlagen:`, error.message);
|
||||
try {
|
||||
await notificationService.sendAdminSessionErrorNotification({
|
||||
profileId,
|
||||
profileEmail: credentials?.email,
|
||||
error: error?.message,
|
||||
label: 'restore'
|
||||
});
|
||||
} catch (notifyError) {
|
||||
console.error('[NOTIFY] Admin-Session-Fehler beim Restore konnte nicht gemeldet werden:', notifyError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +324,30 @@ async function sendAdminBookingErrorNotification({ profileId, profileEmail, stor
|
||||
});
|
||||
}
|
||||
|
||||
async function sendAdminSessionErrorNotification({
|
||||
profileId,
|
||||
profileEmail,
|
||||
profileName,
|
||||
sessionId,
|
||||
error,
|
||||
label
|
||||
}) {
|
||||
const profileLabel = profileEmail || profileId || 'Unbekanntes Profil';
|
||||
const messageLines = [
|
||||
'Session-Login fehlgeschlagen.',
|
||||
`Profil: ${profileLabel}.`,
|
||||
profileName ? `Name: ${profileName}.` : null,
|
||||
sessionId ? `Session: ${sessionId}.` : null,
|
||||
label ? `Kontext: ${label}.` : null,
|
||||
`Fehler: ${error || 'Unbekannter Fehler'}.`
|
||||
].filter(Boolean);
|
||||
await sendAdminTelegramNotification({
|
||||
title: 'Fehler beim Session-Login',
|
||||
message: messageLines.join('\n'),
|
||||
priority: 'high'
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sendSlotNotification,
|
||||
sendStoreWatchNotification,
|
||||
@@ -332,5 +356,6 @@ module.exports = {
|
||||
sendDesiredWindowMissedNotification,
|
||||
sendDormantPickupWarning,
|
||||
sendJournalReminderNotification,
|
||||
sendAdminBookingErrorNotification
|
||||
sendAdminBookingErrorNotification,
|
||||
sendAdminSessionErrorNotification
|
||||
};
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
const foodsharingClient = require('./foodsharingClient');
|
||||
const sessionStore = require('./sessionStore');
|
||||
const notificationService = require('./notificationService');
|
||||
|
||||
const ADMIN_SESSION_ERROR_COOLDOWN_MS = 6 * 60 * 60 * 1000;
|
||||
const adminSessionErrorCooldowns = new Map();
|
||||
|
||||
function shouldNotifyAdminSessionError(key) {
|
||||
if (!key) {
|
||||
return false;
|
||||
}
|
||||
const now = Date.now();
|
||||
const lastNotified = adminSessionErrorCooldowns.get(key) || 0;
|
||||
if (now - lastNotified < ADMIN_SESSION_ERROR_COOLDOWN_MS) {
|
||||
return false;
|
||||
}
|
||||
adminSessionErrorCooldowns.set(key, now);
|
||||
return true;
|
||||
}
|
||||
|
||||
function isUnauthorizedError(error) {
|
||||
const status = error?.response?.status;
|
||||
@@ -50,6 +67,22 @@ async function refreshSession(session, { label } = {}) {
|
||||
`[SESSION] Session ${session?.id || 'unbekannt'} konnte nicht erneuert werden${label ? ` (${label})` : ''}:`,
|
||||
error.message
|
||||
);
|
||||
const profileId = session?.profile?.id ? String(session.profile.id) : null;
|
||||
const notifyKey = profileId || session?.id || null;
|
||||
if (shouldNotifyAdminSessionError(notifyKey)) {
|
||||
try {
|
||||
await notificationService.sendAdminSessionErrorNotification({
|
||||
profileId,
|
||||
profileEmail: session?.credentials?.email || session?.profile?.email,
|
||||
profileName: session?.profile?.name,
|
||||
sessionId: session?.id,
|
||||
error: error?.message,
|
||||
label
|
||||
});
|
||||
} catch (notifyError) {
|
||||
console.error('[NOTIFY] Admin-Session-Fehler konnte nicht gemeldet werden:', notifyError.message);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user