Coverage for docs_src/handling_errors/tutorial002.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1from fastapi import FastAPI, HTTPException 1abcde

2 

3app = FastAPI() 1abcde

4 

5items = {"foo": "The Foo Wrestlers"} 1abcde

6 

7 

8@app.get("/items-header/{item_id}") 1abcde

9async def read_item_header(item_id: str): 1abcde

10 if item_id not in items: 1fghijklmno

11 raise HTTPException( 1gikmo

12 status_code=404, 

13 detail="Item not found", 

14 headers={"X-Error": "There goes my error"}, 

15 ) 

16 return {"item": items[item_id]} 1fhjln