Sync fastapi docs from 50fa3f7c on 2026-01-11
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class InternalError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def get_username():
|
||||
try:
|
||||
yield "Rick"
|
||||
except InternalError:
|
||||
print("Oops, we didn't raise again, Britney 😱")
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
def get_item(item_id: str, username: str = Depends(get_username)):
|
||||
if item_id == "portal-gun":
|
||||
raise InternalError(
|
||||
f"The portal gun is too dangerous to be owned by {username}"
|
||||
)
|
||||
if item_id != "plumbus":
|
||||
raise HTTPException(
|
||||
status_code=404, detail="Item not found, there's only a plumbus here"
|
||||
)
|
||||
return item_id
|
||||
Reference in New Issue
Block a user