Skip to content

Commit

Permalink
feat: create a error base class to simplify validation of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Dec 8, 2022
1 parent c68b9ce commit bb74c24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/utils/Errors/FlotsamError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @format */

export class FlotsamError extends Error {
public reported: boolean = false;

constructor(message: string) {
super(message);
}

static validate(error: unknown): error is FlotsamError {
return error instanceof FlotsamError && !error.reported;
}
}
7 changes: 5 additions & 2 deletions src/utils/Errors/FlotsamValidationError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @format */

export class FlotsamValidationError extends Error {
import { FlotsamError } from './FlotsamError';

export class FlotsamValidationError extends FlotsamError {
public name: string = 'FlotsamValidationError';
public reported: boolean = false;

constructor(message: string) {
super(`[Error][Validator] ${message}`);
super(`\x1b[31m[Error][Validator]\x1b[0m ${message}`);
}
}

0 comments on commit bb74c24

Please sign in to comment.