Improve Error Handling and Exception Hierarchy (Issue #364)#365
Merged
Conversation
… fix random import in error_handling example
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.
PR: Improve Error Handling and Exception Hierarchy
Overview
This PR implements improvements to the error handling system in the TradeStation API Python wrapper, addressing issue #364. The changes include a comprehensive exception hierarchy, enhanced error handling throughout the client, and detailed documentation.
What was implemented
Implementation Details
Design Approach
The implementation follows a clean hierarchical design with a base exception class and specialized subclasses for different error types. This approach provides:
Files Changed
src/tradestation/utils/exceptions.pysrc/tradestation/client/http_client.pysrc/tradestation/client/tradestation_client.pysrc/tradestation/__init__.pyexamples/QuickStart/error_handling.pydocs/error_handling.mdCHANGELOG.mdpyproject.tomlException Hierarchy
classDiagram Exception <|-- TradeStationAPIError TradeStationAPIError <|-- TradeStationAuthError TradeStationAPIError <|-- TradeStationRateLimitError TradeStationAPIError <|-- TradeStationResourceNotFoundError TradeStationAPIError <|-- TradeStationValidationError TradeStationAPIError <|-- TradeStationNetworkError TradeStationAPIError <|-- TradeStationServerError TradeStationAPIError <|-- TradeStationTimeoutError TradeStationAPIError <|-- TradeStationStreamError class TradeStationAPIError{ +str message +int status_code +str request_id +original_exception } class TradeStationAuthError{ +str message } class TradeStationRateLimitError{ +str message +float retry_after } class TradeStationValidationError{ +str message +dict validation_errors }Error Handling Flow
sequenceDiagram participant Client participant HttpClient participant API participant ExceptionMapper Client->>+HttpClient: make_request() HttpClient->>+API: HTTP Request API-->>-HttpClient: HTTP Response alt Response is success (2xx) HttpClient-->>Client: Parsed Response else Response is error (4xx/5xx) HttpClient->>ExceptionMapper: map_http_error(status, data) ExceptionMapper-->>HttpClient: Specific Exception HttpClient--xClient: Raise Exception else Network Error HttpClient--xClient: Raise TradeStationNetworkError endTesting
create_streammethod by adding the missingraise_for_status()callHow to test the changes
cd examples/QuickStart python error_handling.pyKnowledge Base Updates
Closes #364