Skip to main content

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

NameTypeDescription
status_codeAnnotated[int, Doc(...)]HTTP status code to send to the client. Read more about it in the FastAPI docs for Handling Errors
detailAnnotated[Any, Doc(...)] = NoneAny 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

NameTypeDescription
status_codeintHTTP status code to send to the client. Read more about it in the FastAPI docs for Handling Errors
detailAny = NoneAny 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