Last two seconds queue for error handler

This commit is contained in:
Jesús Ángel 2019-05-30 12:03:05 +02:00
parent d227c79a4b
commit 7937003827

View File

@ -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 &&