HTTPException
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.
Constructor
Signature
def HTTPException(
status_code: Annotated[int, Doc(...)],
detail: Annotated[Any, Doc(...)] = None,
headers: Annotated[Mapping[str, str]| None, Doc(...)] = None
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| status_code | Annotated[int, Doc(...)] | HTTP status code to send to the client. Read more about it in the FastAPI docs for Handling Errors |
| detail | Annotated[Any, Doc(...)] = None | Any data to be sent to the client in the detail key of the JSON response. Read more about it in the FastAPI docs for Handling Errors |
| headers | `Annotated[Mapping[str, str] | None, Doc(...)]` = None |
Signature
def HTTPException(
status_code: int,
detail: Any = None,
headers: Mapping[str, str]| None = None
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| status_code | int | HTTP status code to send to the client. Read more about it in the FastAPI docs for Handling Errors |
| detail | Any = None | Any data to be sent to the client in the detail key of the JSON response. Read more about it in the FastAPI docs for Handling Errors |
| headers | `Mapping[str, str] | None` = None |