An HTTP exception you can raise in your own code to show errors to the client. This is for client errors, invalid authentication, invalid data, etc. Not for server errors in your code. Read more about it in the [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tu
| 15 | |
| 16 | |
| 17 | class HTTPException(StarletteHTTPException): |
| 18 | """ |
| 19 | An HTTP exception you can raise in your own code to show errors to the client. |
| 20 | |
| 21 | This is for client errors, invalid authentication, invalid data, etc. Not for server |
| 22 | errors in your code. |
| 23 | |
| 24 | Read more about it in the |
| 25 | [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/). |
| 26 | |
| 27 | ## Example |
| 28 | |
| 29 | ```python |
| 30 | from fastapi import FastAPI, HTTPException |
| 31 | |
| 32 | app = FastAPI() |
| 33 | |
| 34 | items = {"foo": "The Foo Wrestlers"} |
| 35 | |
| 36 | |
| 37 | @app.get("/items/{item_id}") |
| 38 | async def read_item(item_id: str): |
| 39 | if item_id not in items: |
| 40 | raise HTTPException(status_code=404, detail="Item not found") |
| 41 | return {"item": items[item_id]} |
| 42 | ``` |
| 43 | """ |
| 44 | |
| 45 | def __init__( |
| 46 | self, |
| 47 | status_code: Annotated[ |
| 48 | int, |
| 49 | Doc( |
| 50 | """ |
| 51 | HTTP status code to send to the client. |
| 52 | |
| 53 | Read more about it in the |
| 54 | [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#use-httpexception) |
| 55 | """ |
| 56 | ), |
| 57 | ], |
| 58 | detail: Annotated[ |
| 59 | Any, |
| 60 | Doc( |
| 61 | """ |
| 62 | Any data to be sent to the client in the `detail` key of the JSON |
| 63 | response. |
| 64 | |
| 65 | Read more about it in the |
| 66 | [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#use-httpexception) |
| 67 | """ |
| 68 | ), |
| 69 | ] = None, |
| 70 | headers: Annotated[ |
| 71 | Mapping[str, str] | None, |
| 72 | Doc( |
| 73 | """ |
| 74 | Any headers to send to the client in the response. |
no outgoing calls
searching dependent graphs…