Skip to content

Improving ConnectorClient and UserTokenClient error handling - #512

Merged
Rodrigo Brandão (rodrigobr-msft) merged 1 commit into
mainfrom
users/robrandao/handle-request-errors
Jul 31, 2026
Merged

Improving ConnectorClient and UserTokenClient error handling#512
Rodrigo Brandão (rodrigobr-msft) merged 1 commit into
mainfrom
users/robrandao/handle-request-errors

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

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:

  • Added a new utility function _handle_request_error in _utils.py to centralize and standardize HTTP response error handling for all connector client methods.
  • Updated all client methods in agent_sign_in.py and connector_client.py to 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:

  • Changed attachment and transcript upload methods to use .model_dump() for serializing AttachmentData and Transcript objects, ensuring proper field mapping and cleaner code. (Fe969ef8L455, Fe969ef8L695)
  • Removed the redundant local AttachmentData class from connector_client.py in favor of using the imported model. (Fe969ef8L43)

Other updates:

  • Improved handling of HTTP 301/302 redirects in get_attachment to log a warning and return an empty BytesIO object instead of raising an error. (Fe969ef8L129)
  • Updated method signatures to use the correct model types, such as changing the body parameter of send_conversation_history to use the Transcript model. (Fe969ef8L664)

These changes improve code maintainability, consistency, and correctness in handling HTTP responses and data serialization.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_error utility 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.

Comment thread tests/hosting_core/connector/test_connector_client.py
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit d6a820e into main Jul 31, 2026
11 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/handle-request-errors branch July 31, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve difference in status code error handling for UserToken/Connector clients between Python and .NET

3 participants