Improved UserTokenClient and ConnectorClient status code error handling#202
Conversation
…into users/robrandao/client-error-handling
There was a problem hiding this comment.
Pull Request Overview
This pull request standardizes error handling and logging practices across the UserTokenClient and ConnectorClient modules. The changes improve consistency in HTTP response validation and adopt parameterized logging for better performance.
- Refined HTTP status code checks from
>= 400to>= 300or explicit status lists for more accurate error detection - Converted f-string logging to parameterized logging to improve performance when logging is disabled
- Enhanced 404 response handling to return empty TokenResponse objects instead of raising errors
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| user_token_client.py | Updated status code checks from >= 400 to >= 300, converted all logging to parameterized format, and improved 404 handling to return empty TokenResponse objects |
| connector_client.py | Changed status code validation to use explicit success lists ([200, 201, 202]) for write operations and >= 300 for read operations, converted logging to parameterized format |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py
Outdated
Show resolved
Hide resolved
...osoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py
Outdated
Show resolved
Hide resolved
...soft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py
Outdated
Show resolved
Hide resolved
...soft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py
Outdated
Show resolved
Hide resolved
…into users/robrandao/client-error-handling
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 21 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request updates the error handling and logging conventions in the connector and user token client modules to improve consistency and reliability when interacting with HTTP endpoints. The main changes involve refining status code checks for HTTP responses and switching logging statements from f-strings to parameterized logging for better performance and clarity.
Error Handling Improvements:
connector_client.pyanduser_token_client.pyto use more precise ranges or explicit status lists (e.g., changed from>= 400to>= 300or[200, 201, 202]), ensuring errors are caught more accurately and handling is consistent across all client methods. [1] [2] [3] [4] [5]Logging Consistency and Performance:
"Error: %s", error_val) to improve logging performance and avoid unnecessary string interpolation when logging is disabled. This change applies to both info and error log statements in both client modules. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]Response Handling Adjustments:
TokenResponseobjects instead of raising errors), making the client more robust to expected error scenarios. [1] [2]Code Consistency:
connector_client.pyanduser_token_client.py) now follow the same conventions for error checking, logging, and raising exceptions, reducing the likelihood of subtle bugs and making the code easier to maintain. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23]