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
8 changes: 8 additions & 0 deletions jbi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@ async def validation_exception_handler(
errors in order to log some information about malformed
requests.
"""
try:
request_body = (await request.body()).decode("utf8")
except UnicodeDecodeError: # pragma: no cover
# In theory FastAPI would have returned a 400 before doing
# model validation.
request_body = "<invalid unicode>"

logger.error(
"invalid incoming request: %s",
exc,
extra={
"errors": exc.errors(),
"body": request_body,
},
)
return JSONResponse(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_422_errors_are_logged(authenticated_client, webhook_request_factory, ca
logged.errors[0]["msg"]
== "Input should be a valid dictionary or object to extract fields from"
)
assert '"bug":null' in logged.body


@pytest.mark.parametrize(
Expand Down
Loading