mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-27 23:39:17 -05:00
✨ Add HTTPException with custom headers (#35)
* 📝 Update Release Notes with issue templates * ✨ Add HTTPException with support for headers Including docs and tests * 📝 Update Security docs to use new HTTPException
This commit is contained in:
committed by
GitHub
parent
7edbd9345b
commit
8772e2f2ee
12
docs/src/handling_errors/tutorial001.py
Normal file
12
docs/src/handling_errors/tutorial001.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
items = {"foo": "The Foo Wrestlers"}
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def create_item(item_id: str):
|
||||
if item_id not in items:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {"item": items[item_id]}
|
||||
Reference in New Issue
Block a user