Skip to content

Commit

Permalink
Update web.py
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr authored Nov 2, 2024
1 parent 8acd08b commit c86435a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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={
Expand Down

0 comments on commit c86435a

Please sign in to comment.