Skip to content
Discussion options

You must be logged in to vote

@callumforrester based on the docs example, the closest and simple thing you can do is something like that

@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request, exc: RequestValidationError):
    message = f"{len(exc.errors())} validation errors:\n"
    for err in exc.errors():
        error_type = err.get("type", "Unknown")
        error_location = err.get("loc", ("", ""))
        error_message = err.get("msg", "")
        message+="%s -> %s\n" % error_location
        message += f"  {error_message}  (type={error_type})\n"
    return PlainTextResponse(message, status_code=400)
1 validation errors:
path -> item_id
  Input should be a valid integer, …

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@luzzodev
Comment options

@Trinkes
Comment options

@callumforrester
Comment options

@luzzodev
Comment options

Answer selected by YuriiMotov
@callumforrester
Comment options

@luzzodev
Comment options

@callumforrester
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants