mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Last two seconds queue for error handler
This commit is contained in:
parent
d227c79a4b
commit
7937003827
@ -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 &&
|
||||
|
Loading…
Reference in New Issue
Block a user