mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-16 04:53:11 -04:00
📝 Update docs about re-raising validation errors, do not include string as is to not leak information (#14487)
This commit is contained in:
committed by
GitHub
parent
4a98a66778
commit
cd9d093f60
@@ -12,8 +12,11 @@ async def http_exception_handler(request, exc):
|
||||
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_exception_handler(request, exc):
|
||||
return PlainTextResponse(str(exc), status_code=400)
|
||||
async def validation_exception_handler(request, exc: RequestValidationError):
|
||||
message = "Validation errors:"
|
||||
for error in exc.errors():
|
||||
message += f"\nField: {error['loc']}, Error: {error['msg']}"
|
||||
return PlainTextResponse(message, status_code=400)
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
|
||||
Reference in New Issue
Block a user