Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/api/middleware/exception_handling_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Comment thread
krishan711 marked this conversation as resolved.
response = self._convert_exception(exception=kibaException)
Comment thread
krishan711 marked this conversation as resolved.
Comment thread
krishan711 marked this conversation as resolved.
return response
4 changes: 0 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading