mirror of
https://github.com/fastapi/fastapi.git
synced 2026-10-16 07:02:00 -04:00
📝 Update source examples and docs from Python 3.9 to 3.10 (#14900)
This commit is contained in:
1 parent
d06ab3f5c7
commit
c9e2277d8b
655 files changed
+3703
-5660
No files matched your search
@@ -0,0 +1,25 @@
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_exception_handler(request: Request, exc: RequestValidationError):
|
||||
return JSONResponse(
|
||||
status_code=422,
|
||||
content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
|
||||
)
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
title: str
|
||||
size: int
|
||||
|
||||
|
||||
@app.post("/items/")
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
Reference in new issue
Block a user