Debian Codegraph @

docs_src/handling_errors/tutorial002_py310.py

raw
1 from fastapi import FastAPI, HTTPException
2
3 app = FastAPI()
4
5 items = {"foo": "The Foo Wrestlers"}
6
7
8 @app.get("/items-header/{item_id}")
9 async def read_item_header(item_id: str):
10 if item_id not in items:
11 raise HTTPException(
12 status_code=404,
13 detail="Item not found",
14 headers={"X-Error": "There goes my error"},
15 )
16 return {"item": items[item_id]}