Improving ConnectorClient and UserTokenClient error handling - #512
Merged
Rodrigo Brandão (rodrigobr-msft) merged 1 commit intoJul 31, 2026
Merged
Conversation
Copilot started reviewing on behalf of
Rodrigo Brandão (rodrigobr-msft)
July 31, 2026 16:53
View session
Rodrigo Brandão (rodrigobr-msft)
marked this pull request as ready for review
July 31, 2026 16:53
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Microsoft Agents Hosting Core connector clients to centralize HTTP error handling via a shared _handle_request_error helper, and updates several connector operations to use consistent model-based serialization (notably for attachments and transcripts).
Changes:
- Added a shared
_handle_request_errorutility and updated connector client methods to route non-success HTTP responses through it. - Switched attachment upload and transcript/history upload payload serialization to model-based
.model_dump(...). - Expanded tests to assert externally observable REST contract behavior (requests made, typed responses, and error raising).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/hosting_core/connector/test_user_token_client.py | Adds contract-style tests for token operations and sign-in state encoding. |
| tests/hosting_core/connector/test_connector_client.py | Adds contract-style tests for conversation lifecycle, members, attachments, and unexpected statuses. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/mcs/mcs_connector_client.py | Routes MCS connector error handling through the shared helper. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token.py | Replaces ad-hoc response checks with _handle_request_error and standardizes 404 behavior for missing token. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py | Centralizes response error handling and switches attachment/transcript request bodies to .model_dump(...). |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/agent_sign_in.py | Uses _handle_request_error for non-200 responses. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/_utils.py | Introduces _handle_request_error helper for consistent error raising/logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Kyle Rohn (kylerohn-msft)
approved these changes
Jul 31, 2026
Rodrigo Brandão (rodrigobr-msft)
deleted the
users/robrandao/handle-request-errors
branch
July 31, 2026 20:08
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.
This pull request refactors error handling for HTTP responses in the Microsoft Agents Hosting Core connector clients. It centralizes and standardizes response error handling by introducing a shared utility function, and updates all relevant client methods to use it. Additionally, it updates data serialization for attachment and transcript uploads to use model-based serialization, and removes a redundant class.
Error handling improvements:
_handle_request_errorin_utils.pyto centralize and standardize HTTP response error handling for all connector client methods.agent_sign_in.pyandconnector_client.pyto replace ad-hoc error handling and logging with calls to_handle_request_error, ensuring consistent error reporting and exception raising across the codebase. [1] [2] Fe969ef8L89, Fe969ef8L129, Fe969ef8L216, Fe969ef8L239, Fe969ef8L286, Fe969ef8L342, Fe969ef8L388, Fe969ef8L426, Fe969ef8L455, Fe969ef8L505, Fe969ef8L546, Fe969ef8L582, Fe969ef8L616, Fe969ef8L664, Fe969ef8L695)Data serialization and model usage:
.model_dump()for serializingAttachmentDataandTranscriptobjects, ensuring proper field mapping and cleaner code. (Fe969ef8L455, Fe969ef8L695)AttachmentDataclass fromconnector_client.pyin favor of using the imported model. (Fe969ef8L43)Other updates:
get_attachmentto log a warning and return an emptyBytesIOobject instead of raising an error. (Fe969ef8L129)bodyparameter ofsend_conversation_historyto use theTranscriptmodel. (Fe969ef8L664)These changes improve code maintainability, consistency, and correctness in handling HTTP responses and data serialization.