From a0aa74ad22ec38120cbd6803d6fa3b7b8b0e272b Mon Sep 17 00:00:00 2001 From: Krishan Patel Date: Fri, 23 Jan 2026 08:30:21 +0000 Subject: [PATCH 1/2] . --- core/api/middleware/exception_handling_middleware.py | 10 +++++++++- core/queues/message_queue_processor.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/api/middleware/exception_handling_middleware.py b/core/api/middleware/exception_handling_middleware.py index 6deba92..a080c5d 100644 --- a/core/api/middleware/exception_handling_middleware.py +++ b/core/api/middleware/exception_handling_middleware.py @@ -3,6 +3,7 @@ from starlette.requests import Request from starlette.responses import JSONResponse from starlette.responses import Response +from starlette.types import ASGIApp from core import logging from core.exceptions import ClientException @@ -11,6 +12,10 @@ class ExceptionHandlingMiddleware(BaseHTTPMiddleware): + def __init__(self, app: ASGIApp, shouldSquashClientExceptions: bool = True): + super().__init__(app=app) + self.shouldSquashClientExceptions = shouldSquashClientExceptions + @staticmethod def _convert_exception(exception: KibaException) -> Response: response = JSONResponse(status_code=exception.statusCode, content=exception.to_dict()) @@ -26,7 +31,10 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) - if not hasattr(exception, 'shouldAddCacheHeader') or exception.shouldAddCacheHeader: response.headers['Cache-Control'] = f'max-age={60 * 60 * 24 * 365}' except ClientException as exception: - logging.error(f'{exception.exceptionType} occurred: {exception.message}') + if self.shouldSquashClientExceptions: + logging.error(f'{exception.exceptionType} occurred: {exception.message}') + else: + logging.exception(exception) response = self._convert_exception(exception=exception) except KibaException as exception: logging.exception(exception) diff --git a/core/queues/message_queue_processor.py b/core/queues/message_queue_processor.py index 4e91cb1..caad38d 100644 --- a/core/queues/message_queue_processor.py +++ b/core/queues/message_queue_processor.py @@ -53,8 +53,9 @@ async def _process_message(self, message: MessageType) -> None: statusCode = exception.statusCode if isinstance(exception, KibaException) else 500 logging.error('Caught exception whilst processing message:') logging.exception(exception) + kibaException = KibaException.from_exception(exception=exception) for client in self.notificationClients: - await client.post(messageText=f'Error processing message: {message.command}\n```\n{requestId}\n{message.content}\n{exception}```') + await client.post(messageText=f'Error processing message: {message.command}\n```\n{requestId}\n{message.content}\n{kibaException.message}```') # TODO(krishan711): should possibly reset the visibility timeout duration = time.time() - startTime logging.api(action='MESSAGE', path=message.command, pathPattern=message.command, query=query, response=statusCode, duration=duration) From 61a63f522f881024f9f7e4b91370a50e7ba01f60 Mon Sep 17 00:00:00 2001 From: Krishan Patel Date: Fri, 23 Jan 2026 08:31:38 +0000 Subject: [PATCH 2/2] . --- core/api/middleware/exception_handling_middleware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/api/middleware/exception_handling_middleware.py b/core/api/middleware/exception_handling_middleware.py index a080c5d..85bb769 100644 --- a/core/api/middleware/exception_handling_middleware.py +++ b/core/api/middleware/exception_handling_middleware.py @@ -12,7 +12,7 @@ class ExceptionHandlingMiddleware(BaseHTTPMiddleware): - def __init__(self, app: ASGIApp, shouldSquashClientExceptions: bool = True): + def __init__(self, app: ASGIApp, shouldSquashClientExceptions: bool = True) -> None: super().__init__(app=app) self.shouldSquashClientExceptions = shouldSquashClientExceptions