Skip to content

Commit

Permalink
Added new errors classes relantionship
Browse files Browse the repository at this point in the history
  • Loading branch information
Machi3mfl committed Feb 6, 2023
1 parent d93de10 commit 1a5544a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
12 changes: 9 additions & 3 deletions public/react-services/error-handler/errors/ElasticApiError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export class ElasticApiError extends Error {
constructor(message: string) {
super(message);
import { WazuhError } from './WazuhError';

export class ElasticApiError extends WazuhError {
constructor(error: Error, message: string, code: number) {
super(error,message, code);
// Because we are extending built in class
Object.setPrototypeOf(this, ElasticApiError.prototype);
this.name = this.constructor.name;
}

handleError(){
console.log('Show error');
}
}
12 changes: 9 additions & 3 deletions public/react-services/error-handler/errors/ElasticError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export class ElasticError extends Error {
constructor(message: string) {
super(message);
import { WazuhError } from "./WazuhError";

export class ElasticError extends WazuhError {
constructor(error: Error, message: string, code: number) {
super(error,message, code);
// Because we are extending built in class
Object.setPrototypeOf(this, ElasticError.prototype);
this.name = this.constructor.name;
}

handleError(){
console.log('Show error');
}
}
12 changes: 9 additions & 3 deletions public/react-services/error-handler/errors/WazuhApiError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export class WazuhApiError extends Error {
constructor(message: string) {
super(message);
import { WazuhError } from "./WazuhError";

export class WazuhApiError extends WazuhError {
constructor(error: Error, message: string, code: number) {
super(error,message, code);
// Because we are extending built in class
Object.setPrototypeOf(this, WazuhApiError.prototype);
this.name = this.constructor.name;
}

handleError(){
console.log('Show error');
}
}
23 changes: 23 additions & 0 deletions public/react-services/error-handler/errors/WazuhError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface iWazuhError {
error: Error;
message: string;
code: number;
handleError(): void;
}

export abstract class WazuhError extends Error implements iWazuhError {
error: Error;
message: string;
code: number;
constructor(error: Error, message: string, code: number) {
super(message);
this.error = error;
this.message = message;
this.code = code;
}

/**
* This method decides how to treat the error
*/
abstract handleError(): void;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export class WazuhReportingError extends Error {
constructor(message: string) {
super(message);
import { WazuhError } from "./WazuhError";

export class WazuhReportingError extends WazuhError {
constructor(error: Error, message: string, code: number) {
super(error,message, code);
// Because we are extending built in class
Object.setPrototypeOf(this, WazuhReportingError.prototype);
this.name = this.constructor.name;
}

handleError(){
console.log('Show error');
}
}

0 comments on commit 1a5544a

Please sign in to comment.