From c86435af47f1ee267316512f18d0024a6a8b0102 Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Sat, 2 Nov 2024 05:30:57 -0400 Subject: [PATCH] Update web.py --- agents-api/agents_api/web.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 62011b22..1c774691 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -58,12 +58,14 @@ def make_exception_handler(status_code: int) -> Callable[[Any, Any], Any]: """ async def _handler(request: Request, exc: Exception): - errors = exc.errors() if hasattr(exc, "errors") else [exc] + location = None offending_input = None # Return the deepest matching possibility if isinstance(exc, (ValidationError, RequestValidationError)): + errors = exc.errors() + # Get the deepest matching errors max_depth = max(len(error["loc"]) for error in errors) errors = [error for error in errors if len(error["loc"]) == max_depth] @@ -95,9 +97,12 @@ async def _handler(request: Request, exc: Exception): break offending_input = offending_input[loc] + + # Keep only the message from the error + errors = [error.get("msg", error) for error in errors] - # Keep only the message from the error - errors = [error["msg"] for error in errors] + else: + errors = exc.errors() if hasattr(exc, "errors") else [exc] return JSONResponse( content={