fix: Raise error for non-JSON-serializable parameters#70
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughThe diff changes BaseClient.do to skip JSON serialization when Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes The edits are small and localised: a guard clause and tightened exception handling in one client file, plus straightforward test additions that follow a consistent pattern. Review mainly checks correctness of the guard and error message and that tests properly mock responses. Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)luno_python/base_client.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
luno_python/base_client.py(1 hunks)tests/test_client.py(2 hunks)
🧰 Additional context used
🪛 Ruff (0.14.1)
luno_python/base_client.py
79-79: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🔇 Additional comments (2)
tests/test_client.py (2)
4-4: LGTM!Good addition of the Decimal import to support testing non-serialisable parameters.
225-248: Excellent test coverage for the new error handling.This test thoroughly validates the fix by covering:
- Non-serialisable types that commonly cause issues (Decimal)
- Custom objects
- The None case to ensure it still works correctly
The assertions properly verify that the error messages contain 'JSON-serializable', ensuring developers receive actionable feedback.
Fixes issue #69 by providing clear error messages when parameters cannot be serialized to JSON, instead of silently suppressing the error. Changes: - Catch only TypeError instead of all Exceptions when serializing parameters - Raise TypeError with descriptive message for non-serializable types - Add test cases for Decimal and custom objects - Verify None requests still work correctly 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
3f14a38 to
30cc12f
Compare
|



Summary
Fixes #69 by providing clear error messages when request parameters cannot be serialized to JSON, instead of silently suppressing the error and returning a confusing API error.
Previously, passing non-JSON-serializable types (like
Decimal) would silently fail and setparamstoNone, causing misleading API errors. Now, a clearTypeErroris raised immediately pointing to the serialization issue.Changes
BaseClient.do()to catch onlyTypeErrorinstead of suppressing all exceptionsSummary by CodeRabbit
Bug Fixes
Tests