diff --git a/public/services/error-handler.js b/public/services/error-handler.js index bebae5f544..66fd9de0eb 100644 --- a/public/services/error-handler.js +++ b/public/services/error-handler.js @@ -30,6 +30,7 @@ export class ErrorHandler { this.wzMisc = wzMisc; this.$rootScope = $rootScope; this.checkDaemonsStatus = checkDaemonsStatus; + this.history = []; } /** @@ -88,22 +89,41 @@ export class ErrorHandler { */ handle(error, location, isWarning, silent) { const message = this.extractMessage(error); - if (typeof message === 'string' && message.includes('ERROR3099')) { + const messageIsString = typeof message === 'string'; + + if (messageIsString && message.includes('ERROR3099')) { this.$rootScope.wazuhNotReadyYet = 'Wazuh not ready yet.'; this.$rootScope.$applyAsync(); this.checkDaemonsStatus.makePing(); return; } + const origin = ((error || {}).config || {}).url || ''; + const originIsString = typeof origin === 'string' && origin.length; if (this.wzMisc.getBlankScr()) silent = true; - let text = - typeof message === 'string' && typeof origin === 'string' && origin.length - ? `${message} (${origin})` - : message; + + const hasOrigin = messageIsString && originIsString; + + let text = hasOrigin ? `${message} (${origin})` : message; + if (error.extraMessage) text = error.extraMessage; text = location ? location + '. ' + text : text; - if (!silent) { + + // Current date in milliseconds + const date = new Date().getTime(); + + // Remove errors older than 2s from the error history + this.history = this.history.filter(item => date - item.date <= 2000); + + // Check if the incoming error was already shown in the last two seconds + const recentlyShown = this.history.map(item => item.text).includes(text); + + // If the incoming error was not shown in the last two seconds, add it to the history + !recentlyShown && this.history.push({ text, date }); + + // The error must be shown and the error was not shown in the last two seconds, then show the error + if (!silent && !recentlyShown) { if ( isWarning || (text &&