Skip to content

fix(python): log malformed hosted response bodies at debug - #1805

Open
ThomasHartDev wants to merge 1 commit into
pmxt-dev:mainfrom
ThomasHartDev:fix/hosted-json-payload-debug-log
Open

fix(python): log malformed hosted response bodies at debug#1805
ThomasHartDev wants to merge 1 commit into
pmxt-dev:mainfrom
ThomasHartDev:fix/hosted-json-payload-debug-log

Conversation

@ThomasHartDev

Copy link
Copy Markdown

Fixes #1792

_json_payload in sdks/python/pmxt/_hosted_errors.py swallowed a ValueError from response.json() and returned None with no logging. When the hosted trading API returned a non-JSON or malformed body, the resulting HostedTradingError lost all detail about the raw response, which makes backend contract changes and malformed error responses harder to diagnose.

This adds a module logger and a logger.debug line in the except path so the parse failure is recorded before falling back to None. Behavior is otherwise unchanged: the function still returns None and the error mapping flow is untouched.

I used %s-style logging to match the stdlib logging already used in the SDK (ws_client.py) rather than the dict-arg form in the issue, since that form doesn't fit stdlib % formatting.

Added a test in tests/test_hosted_errors.py that drives a malformed 5xx body through raise_from_response and asserts the debug record is emitted while the HostedTradingError still raises. Verified locally: the full test_hosted_errors.py suite passes (29 tests), and the new test fails without the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

empty-catch: sdks/python/pmxt/_hosted_errors.py:181 — except ValueError: return None in _json_payload silently masks malformed response bodies

1 participant