Skip to content

Commit

Permalink
Adds logging of messageExceptions in the fastapi exception handler.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dannon committed Apr 22, 2024
1 parent 5097cb7 commit d6edf6a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/galaxy/webapps/base/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import stat
import typing
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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, though we could. This
# exception will also be dispatched to Sentry, this just makes logs less
# opaque when one sees a 500.
log.error(f"MessageException: {exc}")
return get_error_response_for_request(request, exc)


Expand Down

0 comments on commit d6edf6a

Please sign in to comment.