diff --git a/core/api/middleware/exception_handling_middleware.py b/core/api/middleware/exception_handling_middleware.py index 85bb769..a372f72 100644 --- a/core/api/middleware/exception_handling_middleware.py +++ b/core/api/middleware/exception_handling_middleware.py @@ -12,9 +12,10 @@ class ExceptionHandlingMiddleware(BaseHTTPMiddleware): - def __init__(self, app: ASGIApp, shouldSquashClientExceptions: bool = True) -> None: + def __init__(self, app: ASGIApp, shouldSquashClientExceptions: bool = True, shouldHideInternalErrors: bool = True) -> None: super().__init__(app=app) self.shouldSquashClientExceptions = shouldSquashClientExceptions + self.shouldHideInternalErrors = shouldHideInternalErrors @staticmethod def _convert_exception(exception: KibaException) -> Response: @@ -38,8 +39,13 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) - response = self._convert_exception(exception=exception) except KibaException as exception: logging.exception(exception) + if self.shouldHideInternalErrors: + exception = KibaException(message='Internal Server Error', statusCode=exception.statusCode, exceptionType=exception.exceptionType) response = self._convert_exception(exception=exception) except Exception as exception: # noqa: BLE001 logging.exception(exception) - response = self._convert_exception(exception=KibaException.from_exception(exception=exception)) + kibaException = KibaException.from_exception(exception=exception) + if self.shouldHideInternalErrors: + kibaException = KibaException(message='Internal Server Error', statusCode=kibaException.statusCode) + response = self._convert_exception(exception=kibaException) return response diff --git a/uv.lock b/uv.lock index 09f66ce..7b72458 100644 --- a/uv.lock +++ b/uv.lock @@ -2,10 +2,6 @@ version = 1 revision = 3 requires-python = ">=3.12, <4" -[options] -exclude-newer = "2026-03-29T09:26:57.277657Z" -exclude-newer-span = "P7D" - [[package]] name = "aiobotocore" version = "3.3.0"