MCPcopy
hub / github.com/fastapi/fastapi / HTTPException

Class HTTPException

fastapi/exceptions.py:17–83  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

15
16
17class 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.

Callers 15

appFunction · 0.90
handleMethod · 0.90
get_responseMethod · 0.90
_lookup_pathMethod · 0.90
handleMethod · 0.90
get_current_userFunction · 0.90
get_current_active_userFunction · 0.90
loginFunction · 0.90

Calls

no outgoing calls

Tested by 11

innerMethod · 0.72
read_itemFunction · 0.72
catching_depFunction · 0.72
raise_after_yieldFunction · 0.72
require_cookieFunction · 0.72
read_usersFunction · 0.72
process_authFunction · 0.72
put_invalid_userFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…