fix(swap): raise error when Jupiter returns empty transaction#196
fix(swap): raise error when Jupiter returns empty transaction#196
Conversation
There was a problem hiding this comment.
Pull request overview
Adds explicit failure handling for an edge case in the Jupiter Ultra V3 order response where the transaction field is present but empty, preventing downstream code from treating an empty transaction as executable.
Changes:
- Raise an exception when a Jupiter order response contains an empty
transaction. - Add a unit test covering the empty-transaction case in the Jupiter client.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
app/api/swap/providers/jupiter/transformations.py |
Fails fast when the Jupiter order response has no usable transaction payload. |
app/api/swap/providers/jupiter/test_client.py |
Adds coverage asserting the client raises on an empty transaction response. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ... | ||
| # raise SwapError | ||
| raise ValueError( | ||
| "Jupiter order response does not contain a transaction", |
There was a problem hiding this comment.
The raised ValueError here drops useful context that’s already available in JupiterOrderResponse (e.g., request_id, error_code, error_message). Consider including those fields in the exception message (or raising a SwapError that carries them) so failures caused by empty transactions can be correlated with Jupiter logs/support requests.
| "Jupiter order response does not contain a transaction", | |
| "Jupiter order response does not contain a transaction; " | |
| f"request_id={getattr(jupiter_response, 'request_id', None)}, " | |
| f"error_code={getattr(jupiter_response, 'error_code', None)}, " | |
| f"error_message={getattr(jupiter_response, 'error_message', None)}", |
| mock_token_manager.get = AsyncMock(return_value=SOL_TOKEN_INFO) | ||
|
|
||
| mock_response = MagicMock() | ||
| mock_response.status_code = 200 | ||
| mock_response.json.return_value = { | ||
| **MOCK_JUPITER_ORDER_RESPONSE, | ||
| "transaction": "", | ||
| } | ||
| mock_httpx_client.get.return_value = mock_response |
There was a problem hiding this comment.
This test sets mock_token_manager.get to always return SOL_TOKEN_INFO, which can mask token-resolution problems (output/route-plan mints are not SOL) and may exercise a different code path than production. Consider using a side_effect (like other tests in this file) that returns SOL/USDC/(optional intermediate) token infos keyed by mint address, while still keeping the test focused on the empty transaction behavior.
Addresses #163 (comment)