Skip to main content

http_exception_handler

Handles HTTP exceptions by returning an appropriate Response or JSONResponse based on the exception's status code and detail, including any specified headers.

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

Handles HTTP exceptions by returning an appropriate HTTP response. This function is used to standardize error responses for HTTP exceptions.

Parameters

NameTypeDescription
requestRequestThe incoming HTTP request object.
excHTTPExceptionThe HTTP exception that was raised, containing details like status code and error message.

Returns

TypeDescription
ResponseAn HTTP response object, either a standard Response for status codes that do not allow a body, or a JSONResponse for others.