Skip to content

Commit 0eec10b

Browse files
committed
📝 Update docs source example
1 parent a83795f commit 0eec10b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs_src/handling_errors/tutorial004.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ async def http_exception_handler(request, exc):
1212

1313

1414
@app.exception_handler(RequestValidationError)
15-
async def validation_exception_handler(request, exc):
16-
return PlainTextResponse(str(exc), status_code=400)
15+
async def validation_exception_handler(request, exc: RequestValidationError):
16+
message = "Validation errors:"
17+
for error in exc.errors():
18+
message += f"\nField: {error['loc']}, Error: {error['msg']}"
19+
return PlainTextResponse(message, status_code=400)
1720

1821

1922
@app.get("/items/{item_id}")

0 commit comments

Comments
 (0)