mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-25 14:31:00 -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
16
docs/src/handling_errors/tutorial002.py
Normal file
16
docs/src/handling_errors/tutorial002.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
items = {"foo": "The Foo Wrestlers"}
|
||||
|
||||
|
||||
@app.get("/items-header/{item_id}")
|
||||
async def create_item_header(item_id: str):
|
||||
if item_id not in items:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Item not found",
|
||||
headers={"X-Error": "There goes my error"},
|
||||
)
|
||||
return {"item": items[item_id]}
|
||||
Reference in New Issue
Block a user