summaryrefslogtreecommitdiffstats
path: root/openbb_platform/core/openbb_core/app/static/utils/decorators.py
diff options
context:
space:
mode:
Diffstat (limited to 'openbb_platform/core/openbb_core/app/static/utils/decorators.py')
-rw-r--r--openbb_platform/core/openbb_core/app/static/utils/decorators.py48
1 files changed, 20 insertions, 28 deletions
diff --git a/openbb_platform/core/openbb_core/app/static/utils/decorators.py b/openbb_platform/core/openbb_core/app/static/utils/decorators.py
index a8fbf1f0d59..8daefae0575 100644
--- a/openbb_platform/core/openbb_core/app/static/utils/decorators.py
+++ b/openbb_platform/core/openbb_core/app/static/utils/decorators.py
@@ -47,8 +47,7 @@ def exception_handler(func: Callable[P, R]) -> Callable[P, R]:
def wrapper(*f_args, **f_kwargs):
try:
return func(*f_args, **f_kwargs)
- except (ValidationError, Exception) as e:
- # If the DEBUG_MODE is enabled, raise the exception with complete traceback
+ except (ValidationError, OpenBBError, Exception) as e:
if Env().DEBUG_MODE:
raise
@@ -60,34 +59,27 @@ def exception_handler(func: Callable[P, R]) -> Callable[P, R]:
if isinstance(e, ValidationError):
error_list = []
-
- validation_error = f"{e.error_count()} validations errors in {e.title}"
- for error in e.errors():
- arg = ".".join(map(str, error["loc"]))
- arg_error = f"Arg {arg} ->\n"
- error_details = (
- f"{error['msg']} "
- f"[validation_error_type={error['type']}, "
- f"input_type={type(error['input']).__name__}, "
- f"input_value={error['input']}]\n"
- )
- url = error.get("url")
- error_info = (
- f" For further information visit {url}\n" if url else ""
+ validation_error = f"{e.error_count()} validations error(s)"
+ for err in e.errors(include_url=False):
+ loc = ".".join(
+ [
+ str(i)
+ for i in err.get("loc", ())
+ if i not in ("standard_params", "extra_params")
+ ]
)
- error_list.append(arg_error + error_details + error_info)
-
+ _input = err.get("input", "")
+ msg = err.get("msg", "")
+ error_list.append(f"[Arg] {loc} -> input: {_input} -> {msg}")
error_list.insert(0, validation_error)
error_str = "\n".join(error_list)
-
- raise OpenBBError(
- f"\nType -> ValidationError \n\nDetails -> {error_str}"
- ).with_traceback(tb) from None
-
- # If the error is not a ValidationError, then it is a generic exception
- error_type = getattr(e, "original", e).__class__.__name__
- raise OpenBBError(
- f"\nType -> {error_type}\n\nDetail -> {str(e)}"
- ).with_traceback(tb) from None
+ raise OpenBBError(f"\n[Error] -> {error_str}").with_traceback(
+ tb
+ ) from None
+ if isinstance(e, OpenBBError):
+ raise OpenBBError(f"\n[Error] -> {str(e)}").with_traceback(tb) from None
+ raise OpenBBError("\n[Error] -> Unexpected error.").with_traceback(
+ tb
+ ) from None
return wrapper