-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/3316 error handler orchestrator (#3327)
* feat(errorBoundary): Added ErrorBoundary HOC and component and added loglevel dependency * feature(errorBoundary): Moved with the others HOCs. * feature(errorBoundary): Typo refactor. * First attempt LoggerService * Merged error boundary, integrated loggerService. * changed logger name, create logger-service test file * Updated CHANGELOG * Moved to react-services, changed name, traslates comments * feat(errorBoundary): Removed old integration * refactor(loggerService): Changed class for function methods. * test(logger-service): Added basic unit test to logger-service * refactor(logger-service): Applied new implementation of error-orchestrator service. * feature(logger-service): PR comments and some refactors. Co-authored-by: gabiwassan <gabriel.wassan@wazuh.com> Co-authored-by: Ibarra Maximiliano <maximiliano.ibarra@wazuh.com>
- Loading branch information
1 parent
028dc0e
commit 7fdbe56
Showing
12 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
public/react-services/error-orchestrator/error-orchestrator-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator base | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { ErrorToastOptions } from 'kibana/public'; | ||
import { UI_LOGGER_LEVELS } from '../../../common/constants'; | ||
import { getToasts } from '../../kibana-services'; | ||
import loglevel from 'loglevel'; | ||
import { GenericRequest } from '../../react-services/generic-request'; | ||
import { ErrorOrchestrator, UIErrorLog } from './types'; | ||
|
||
export class ErrorOrchestratorBase implements ErrorOrchestrator { | ||
public loadErrorLog(errorLog: UIErrorLog) { | ||
if (errorLog.display) this.displayError(errorLog); | ||
if (errorLog.store) this.storeError(errorLog).then(loglevel.info); | ||
} | ||
|
||
public displayError(errorLog: UIErrorLog) { | ||
const toast = { | ||
title: errorLog.error.title, | ||
toastMessage: errorLog.error.message, | ||
toastLifeTimeMs: 3000, | ||
}; | ||
|
||
getToasts().addError(errorLog.error.error, toast as ErrorToastOptions); | ||
} | ||
|
||
public loglevelError(errorLog: UIErrorLog) { | ||
switch (errorLog.level) { | ||
case UI_LOGGER_LEVELS.INFO: | ||
loglevel.info(errorLog.error.message, errorLog.error.error); | ||
break; | ||
case UI_LOGGER_LEVELS.WARNING: | ||
loglevel.warn(errorLog.error.message, errorLog.error.error); | ||
break; | ||
case UI_LOGGER_LEVELS.ERROR: | ||
loglevel.error(errorLog.error.message, errorLog.error.error); | ||
break; | ||
default: | ||
console.log('No error level', errorLog.error.message, errorLog.error.error); | ||
} | ||
} | ||
|
||
private async storeError(errorLog: UIErrorLog) { | ||
try { | ||
await GenericRequest.request('POST', `/utils/logs/ui`, { | ||
body: { | ||
message: errorLog.error.message, | ||
level: errorLog.level, | ||
location: errorLog.location, | ||
}, | ||
}); | ||
} catch (error) { | ||
loglevel.error('Failed on request [POST /utils/logs/ui]', error); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
public/react-services/error-orchestrator/error-orchestrator-business.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator for business implementation | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { ErrorOrchestratorBase } from './error-orchestrator-base'; | ||
import { UIErrorLog } from './types'; | ||
|
||
export class ErrorOrchestratorBusiness extends ErrorOrchestratorBase { | ||
public displayError(errorLog: UIErrorLog) { | ||
super.displayError(errorLog); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
public/react-services/error-orchestrator/error-orchestrator-critical.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator for critical implementation | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { ErrorOrchestratorBase } from './error-orchestrator-base'; | ||
import { UIErrorLog } from './types'; | ||
|
||
export class ErrorOrchestratorCritical extends ErrorOrchestratorBase { | ||
public displayError(errorLog: UIErrorLog) { | ||
// continue here with the integration with the error-boundary hoc/component | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
public/react-services/error-orchestrator/error-orchestrator-ui.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator for UI implementation | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { ErrorOrchestratorBase } from './error-orchestrator-base'; | ||
import { UIErrorLog } from './types'; | ||
|
||
export class ErrorOrchestratorUI extends ErrorOrchestratorBase { | ||
public displayError(errorLog: UIErrorLog) { | ||
super.displayError(errorLog); | ||
} | ||
|
||
public loglevelError(errorLog: UIErrorLog) { | ||
super.loglevelError(errorLog); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
public/react-services/error-orchestrator/error-orchestrator.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator factory | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { ErrorOrchestratorUI } from './error-orchestrator-ui'; | ||
import { ErrorOrchestratorBusiness } from './error-orchestrator-business'; | ||
import { ErrorOrchestratorCritical } from './error-orchestrator-critical'; | ||
import { ErrorOrchestrator, UI_ERROR_SEVERITIES, UIErrorSeverity } from './types'; | ||
|
||
export const errorOrchestratorFactory = (severity: UIErrorSeverity): ErrorOrchestrator => { | ||
switch (severity) { | ||
case UI_ERROR_SEVERITIES.UI: | ||
return new ErrorOrchestratorUI(); | ||
case UI_ERROR_SEVERITIES.BUSINESS: | ||
return new ErrorOrchestratorBusiness(); | ||
case UI_ERROR_SEVERITIES.CRITICAL: | ||
return new ErrorOrchestratorCritical(); | ||
default: | ||
break; | ||
} | ||
}; |
23 changes: 23 additions & 0 deletions
23
public/react-services/error-orchestrator/error-orchestrator.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Wazuh app - Error Orchestrator service | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import { errorOrchestratorFactory } from './error-orchestrator.factory'; | ||
import { ErrorOrchestrator, UIErrorLog } from './types'; | ||
|
||
export class ErrorOrchestratorClass { | ||
public constructor() {} | ||
|
||
public handleError(uiErrorLog: UIErrorLog) { | ||
const errorOrchestrator: ErrorOrchestrator = errorOrchestratorFactory(uiErrorLog.severity); | ||
errorOrchestrator.loadErrorLog(uiErrorLog); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Wazuh app - Error logger types | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
type WARNING = 'WARNING'; | ||
type INFO = 'INFO'; | ||
type ERROR = 'ERROR'; | ||
export type UILogLevel = WARNING | INFO | ERROR; | ||
|
||
type UI = 'UI'; | ||
type BUSINESS = 'BUSINESS'; | ||
type CRITICAL = 'CRITICAL'; | ||
export type UIErrorSeverity = UI | BUSINESS | CRITICAL; | ||
export const UI_ERROR_SEVERITIES = { | ||
UI: 'UI', | ||
BUSINESS: 'BUSINESS', | ||
CRITICAL: 'CRITICAL', | ||
}; | ||
|
||
export type UIError = { | ||
message: string; | ||
error: any; | ||
title?: string; | ||
}; | ||
|
||
export type UIErrorLog = { | ||
context: string; | ||
level: UILogLevel; | ||
severity: UIErrorSeverity; | ||
display?: boolean; | ||
store?: boolean; | ||
error: UIError; | ||
location: string; | ||
}; | ||
|
||
export type ErrorOrchestrator = { | ||
loadErrorLog: (uiErrorLog: UIErrorLog) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { GenericRequest } from './generic-request'; | ||
export { WzRequest } from './wz-request'; | ||
export { ErrorHandler } from './error-handler'; | ||
export { formatUIDate } from './time-service'; | ||
export { formatUIDate } from './time-service'; | ||
export { ErrorOrchestratorClass } from './error-orchestrator/error-orchestrator.service'; |