-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BugFix: Updated API Error Handling In Response (#1323)
Errors now bubbling up to the frontend, includes validation errors
- Loading branch information
Showing
5 changed files
with
92 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export class BaseError extends Error { | ||
errors: (string | object)[] = []; | ||
|
||
constructor(name: string, message: string, errors?: (string | object)[], stack?: string) { | ||
super(message); | ||
|
||
this.name = name; | ||
|
||
for (const error of errors ?? []) { | ||
if (error instanceof Error) { | ||
// By default, properties of Error objects are not enumerable, so we need to manually extract them. | ||
this.errors.push({ name: error.name, message: error.message }); | ||
} else { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
// If a stack is provided, use it. Otherwise, generate a new stack trace. | ||
if (stack) { | ||
this.stack = stack; | ||
} else { | ||
Error.captureStackTrace(this); | ||
} | ||
} | ||
} |
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