Skip to content

Instantly share code, notes, and snippets.

@calderaro
Created September 10, 2020 14:46
Show Gist options
  • Save calderaro/9451cd99c42663e21eb6089d9267e2d9 to your computer and use it in GitHub Desktop.
Save calderaro/9451cd99c42663e21eb6089d9267e2d9 to your computer and use it in GitHub Desktop.
CustomError.ts
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