Skip to main content

http_exception_handler

Handles HTTP exceptions by returning a JSON response containing the error details or an empty response if the status code does not allow a body.

def http_exception_handler(
request: Request,
exc: HTTPException
) - > Response

Handles HTTP exceptions by returning a standardized response, ensuring the response body is omitted for status codes that do not allow it.

Parameters​

NameTypeDescription
requestRequestThe incoming HTTP request object that triggered the exception.
excHTTPExceptionThe exception instance containing the status code, detail message, and optional headers to be returned to the client.

Returns​

TypeDescription
ResponseA JSONResponse containing the error details, or a plain Response if the status code prohibits a body.