Skip to content

Commit

Permalink
[BugFix] Handle ValidationError Better (#6955)
Browse files Browse the repository at this point in the history
* handle validation error

* distinguish data model
  • Loading branch information
deeleeramone authored Nov 25, 2024
1 parent 6fa993d commit 7d8202f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions openbb_platform/core/openbb_core/app/static/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def wrapper(*f_args, **f_kwargs):
while tb.tb_next is not None:
tb = tb.tb_next

if isinstance(e, ValidationError) and "Data" not in e.title:
error_list = []
if isinstance(e, ValidationError):
error_list: list = []
validation_error = f"{e.error_count()} validations error(s)"
for err in e.errors(include_url=False):
loc = ".".join(
Expand All @@ -80,25 +80,26 @@ def wrapper(*f_args, **f_kwargs):
if msg == "Missing required argument"
else err.get("input", "")
)
error_list.append(f"[Arg] {loc} -> input: {_input} -> {msg}")
prefix = f"[Data Model] {e.title}\n" if "Data" in e.title else ""
error_list.append(
f"{prefix}[Arg] {loc} -> input: {_input} -> {msg}"
)
error_list.insert(0, validation_error)
error_str = "\n".join(error_list)
raise OpenBBError(f"\n[Error] -> {error_str}").with_traceback(
tb
) from None
if isinstance(e, UnauthorizedError):
raise UnauthorizedError(f"\n[Error] -> {str(e)}").with_traceback(
raise UnauthorizedError(f"\n[Error] -> {e}").with_traceback(
tb
) from None
if isinstance(e, EmptyDataError):
raise EmptyDataError(f"\n[Empty] -> {str(e)}").with_traceback(
tb
) from None
raise EmptyDataError(f"\n[Empty] -> {e}").with_traceback(tb) from None
if isinstance(e, OpenBBError):
raise OpenBBError(f"\n[Error] -> {str(e)}").with_traceback(tb) from None
raise OpenBBError(f"\n[Error] -> {e}").with_traceback(tb) from None
if isinstance(e, Exception):
raise OpenBBError(
f"\n[Unexpected Error] -> {e.__class__.__name__} -> {str(e.args[0] or e.args)}"
f"\n[Unexpected Error] -> {e.__class__.__name__} -> {e}"
).with_traceback(tb) from None

return None
Expand Down

0 comments on commit 7d8202f

Please sign in to comment.