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
| Name | Type | Description |
|---|---|---|
| request | Request | The incoming HTTP request object that triggered the exception. |
| exc | HTTPException | The exception instance containing the status code, detail message, and optional headers to be returned to the client. |
Returns
| Type | Description |
|---|---|
Response | A JSONResponse containing the error details, or a plain Response if the status code prohibits a body. |