From 352c505fc6b6c26b64b06ee21caa0a330ab17751 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Mon, 22 Apr 2024 17:32:26 -0400 Subject: [PATCH] Adds logging of messageExceptions in the fastapi exception handler. We're intentionally not doing a full log.exception with the traceback here, though we could. This exception will also be dispatched to Sentry if configured, this just makes logs less opaque when one sees a 500. --- lib/galaxy/webapps/base/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/galaxy/webapps/base/api.py b/lib/galaxy/webapps/base/api.py index 7923fc297331..f440d3755a7b 100644 --- a/lib/galaxy/webapps/base/api.py +++ b/lib/galaxy/webapps/base/api.py @@ -1,3 +1,4 @@ +import logging import os import stat import typing @@ -32,6 +33,9 @@ ) +log = logging.getLogger(__name__) + + # Copied from https://github.com/tiangolo/fastapi/issues/1240#issuecomment-1055396884 def _get_range_header(range_header: str, file_size: int) -> typing.Tuple[int, int]: def _invalid_range(): @@ -189,6 +193,10 @@ async def validate_exception_middleware(request: Request, exc: RequestValidation @app.exception_handler(MessageException) async def message_exception_middleware(request: Request, exc: MessageException) -> Response: + # Intentionally not logging traceback here as the full context will be + # dispatched to Sentry if configured. This just makes logs less opaque + # when one sees a 500. + log.error(f"MessageException: {exc}") return get_error_response_for_request(request, exc)