I want to log my exceptions, but also log the request headers and body when an exception occurs. Basically what LoggingMiddlewareConfig does, but only when an exception occurs.
I tried to go the route of the example here - https://github.com/litestar-org/litestar-pg-redis-docker/blob/78094bc4ea82839ba8703a41381da1e60f0b1d4d/app/core/exceptions.py
Here's my code
async def logging_exception_handler(request: Request, exc: Exception) -> Response[Any]:
logging_middleware_config = LoggingMiddlewareConfig()
extracted_data = await logging_middleware_config.middleware_class.extract_request_data(request)
logging_middleware_config.middleware_class.log_message(values=extracted_data)
logger.error("Application Exception", exc_info=exc)
return ExceptionHandlerMiddleware(
app=request.app, debug=request.app.debug, exception_handlers={}
).default_http_exception_handler(request, exc)
However, the problem is that the exception handler cannot be async. At the same time it seems that I need to await the request body in this handler, so I'm kinda stuck in a pickle.
No response
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too