diff --git a/backend/app/core/operation.py b/backend/app/core/operation.py index e49a8a9..ae55759 100644 --- a/backend/app/core/operation.py +++ b/backend/app/core/operation.py @@ -11,25 +11,25 @@ import json class LoggingMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): - if request.method in ("POST", "PUT", "PATCH","DELETE"): - try: - request.state.body = await request.json() - except json.JSONDecodeError: - request.state.body = await request.body() - else: - request.state.body = None - + if request.method in ("POST", "PUT", "PATCH","DELETE"): try: - response = await call_next(request) - state = request.state - except Exception as e: - await self.log_error(request, e) - raise - - if hasattr(request.state, "user") and hasattr(request.state, "tenant"): - await self.log_request(request, response,state) + request.state.body = await request.json() + except json.JSONDecodeError: + request.state.body = await request.body() + else: + request.state.body = None - return response + try: + response = await call_next(request) + state = request.state + except Exception as e: + await self.log_error(request, e) + raise + + if hasattr(request.state, "user") and hasattr(request.state, "tenant"): + await self.log_request(request, response,state) + + return response async def log_request(self, request: Request, response,state): try: