feat: structured OMS error handling with exception hierarchy#158
Open
feat: structured OMS error handling with exception hierarchy#158
Conversation
farnyser
approved these changes
Apr 7, 2026
- New tplus/exceptions.py: OmsError base class with subclasses
(OrderRejected, AuthError, RateLimitError, NotFoundError, ServerError)
- Updated base.py: parse {"error": {...}} response shape, raise typed
exceptions with code/message/details/retryable fields
- Updated orderbook.py: handle NotFoundError for 404 responses
- 31 new tests for error classification and response parsing
get_user_inventory, get_user_solvency, get_user_margin_info now catch NotFoundError and return empty results instead of raising, matching the pre-existing pattern in get_user_orders_for_book. This maintains backward compatibility for callers that expect empty data for unknown users.
OmsError now inherits from httpx.HTTPStatusError, so existing except HTTPStatusError blocks in E2E tests and other consumers continue to work. The .response attribute is always available. Also catch NotFoundError in get_user_trades/get_user_orders.
b38ddec to
2561ffc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to tpluslabs/tplus-core#953