Created
September 10, 2020 14:46
-
-
Save calderaro/9451cd99c42663e21eb6089d9267e2d9 to your computer and use it in GitHub Desktop.
CustomError.ts
This file contains hidden or 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
export default class CustomError extends Error { | |
code = ''; | |
errors: { [key: string]: string[] } = {}; | |
length = 0; | |
constructor(message: string, code: string) { | |
super(message); | |
this.code = code; | |
} | |
setError = (key: string, message: string) => { | |
this.length++; | |
if (this.errors[key]) { | |
this.errors[key] = [...this.errors[key], message]; | |
} else { | |
this.errors[key] = [message]; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment