From e587b540697cb45a4966ed547a9ce2d241025b29 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Thu, 23 Oct 2025 09:43:45 -0700 Subject: [PATCH 1/5] Modifying error checking in connector and user token clients --- .../core/connector/client/connector_client.py | 61 +++++++++++-------- .../connector/client/user_token_client.py | 47 +++++++------- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index a93eb1a8..3f0b1e3b 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -76,7 +76,7 @@ async def get_attachment_info(self, attachment_id: str) -> AttachmentInfo: logger.info(f"Getting attachment info for ID: {attachment_id}") async with self.client.get(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error getting attachment info: {response.status}", stack_info=True ) @@ -110,7 +110,7 @@ async def get_attachment(self, attachment_id: str, view_id: str) -> BytesIO: logger.info(f"Getting attachment for ID: {attachment_id}, View ID: {view_id}") async with self.client.get(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error getting attachment: {response.status}", stack_info=True ) @@ -146,7 +146,7 @@ async def get_conversations( f"Getting conversations with continuation token: {continuation_token}" ) async with self.client.get("v3/conversations", params=params) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error getting conversations: {response.status}", stack_info=True ) @@ -170,7 +170,7 @@ async def create_conversation( "v3/conversations", json=body.model_dump(by_alias=True, exclude_unset=True, mode="json"), ) as response: - if response.status >= 400: + if response.status not in [200, 201, 202]: logger.error( f"Error creating conversation: {response.status}", stack_info=True ) @@ -212,7 +212,7 @@ async def reply_to_activity( ) as response: result = await response.json() if response.content_length else {} - if response.status >= 400: + if response.status not in [200, 201, 202]: logger.error( f"Error replying to activity: {result or response.status}", stack_info=True, @@ -252,7 +252,7 @@ async def send_to_conversation( url, json=body.model_dump(by_alias=True, exclude_unset=True, mode="json"), ) as response: - if response.status >= 400: + if response.status not in [200, 201, 202]: logger.error( f"Error sending to conversation: {response.status}", stack_info=True ) @@ -289,7 +289,7 @@ async def update_activity( url, json=body.model_dump(by_alias=True, exclude_unset=True), ) as response: - if response.status >= 400: + if response.status not in [200, 201, 202]: logger.error( f"Error updating activity: {response.status}", stack_info=True ) @@ -319,7 +319,7 @@ async def delete_activity(self, conversation_id: str, activity_id: str) -> None: f"Deleting activity: {activity_id} from conversation: {conversation_id}" ) async with self.client.delete(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error deleting activity: {response.status}", stack_info=True ) @@ -354,12 +354,14 @@ async def upload_attachment( } logger.info( - f"Uploading attachment to conversation: {conversation_id}, Attachment name: {body.name}" + "Uploading attachment to conversation: %s, Attachment name: %s", + conversation_id, + body.name, ) async with self.client.post(url, json=attachment_dict) as response: - if response.status >= 400: + if response.status not in [200, 201, 202]: logger.error( - f"Error uploading attachment: {response.status}", stack_info=True + "Error uploading attachment: %s", response.status, stack_info=True ) response.raise_for_status() @@ -385,11 +387,14 @@ async def get_conversation_members( conversation_id = self._normalize_conversation_id(conversation_id) url = f"v3/conversations/{conversation_id}/members" - logger.info(f"Getting conversation members for conversation: {conversation_id}") + logger.info( + "Getting conversation members for conversation: %s", conversation_id + ) async with self.client.get(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( - f"Error getting conversation members: {response.status}", + "Error getting conversation members: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -418,12 +423,15 @@ async def get_conversation_member( url = f"v3/conversations/{conversation_id}/members/{member_id}" logger.info( - f"Getting conversation member: {member_id} from conversation: {conversation_id}" + "Getting conversation member: %s from conversation: %s", + member_id, + conversation_id, ) async with self.client.get(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( - f"Error getting conversation member: {response.status}", + "Error getting conversation member: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -451,12 +459,15 @@ async def delete_conversation_member( url = f"v3/conversations/{conversation_id}/members/{member_id}" logger.info( - f"Deleting conversation member: {member_id} from conversation: {conversation_id}" + "Deleting conversation member: %s from conversation: %s", + member_id, + conversation_id, ) async with self.client.delete(url) as response: - if response.status >= 400 and response.status != 204: + if response.status not in [200, 204]: logger.error( - f"Error deleting conversation member: {response.status}", + f"Error deleting conversation member: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -485,7 +496,7 @@ async def get_activity_members( f"Getting activity members for conversation: {conversation_id}, Activity ID: {activity_id}" ) async with self.client.get(url) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error getting activity members: {response.status}", stack_info=True, @@ -529,7 +540,7 @@ async def get_conversation_paged_members( f"Getting paged members for conversation: {conversation_id}, Page Size: {page_size}, Continuation Token: {continuation_token}" ) async with self.client.get(url, params=params) as response: - if response.status >= 400: + if response.status >= 300: logger.error( f"Error getting conversation paged members: {response.status}", stack_info=True, @@ -561,11 +572,7 @@ async def send_conversation_history( logger.info(f"Sending conversation history to conversation: {conversation_id}") async with self.client.post(url, json=body) as response: - if ( - response.status >= 400 - and response.status != 201 - and response.status != 202 - ): + if response.status not in [200, 201, 202]: logger.error( f"Error sending conversation history: {response.status}", stack_info=True, diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py index 0d1b8c4c..c8e933f7 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py @@ -58,7 +58,7 @@ async def get_sign_in_url( async with self.client.get( "api/agentsignin/getSignInUrl", params=params ) as response: - if response.status >= 400: + if response.status >= 300: logger.error(f"Error getting sign-in URL: {response.status}") response.raise_for_status() @@ -89,13 +89,14 @@ async def get_sign_in_resource( params["finalRedirect"] = final_redirect logger.info( - f"AgentSignIn.get_sign_in_resource(): Getting sign-in resource with params: {params}" + "AgentSignIn.get_sign_in_resource(): Getting sign-in resource with params: %s", + params, ) async with self.client.get( "api/botsignin/getSignInResource", params=params ) as response: - if response.status >= 400: - logger.error(f"Error getting sign-in resource: {response.status}") + if response.status >= 300: + logger.error("Error getting sign-in resource: %s", response.status) response.raise_for_status() data = await response.json() @@ -122,12 +123,12 @@ async def get_token( if code: params["code"] = code - logger.info(f"User_token.get_token(): Getting token with params: {params}") + logger.info("User_token.get_token(): Getting token with params: %s", params) async with self.client.get("api/usertoken/GetToken", params=params) as response: if response.status == 404: - return TokenResponse(model_validate={}) - if response.status >= 400: - logger.error(f"Error getting token: {response.status}") + return TokenResponse() + if response.status >= 300: + logger.error("Error getting token: %s", response.status) response.raise_for_status() data = await response.json() @@ -179,12 +180,12 @@ async def get_aad_tokens( if channel_id: params["channelId"] = channel_id - logger.info(f"Getting AAD tokens with params: {params} and body: {body}") + logger.info("Getting AAD tokens with params: %s and body: %s", params, body) async with self.client.post( "api/usertoken/GetAadTokens", params=params, json=body ) as response: - if response.status >= 400: - logger.error(f"Error getting AAD tokens: {response.status}") + if response.status >= 300: + logger.error("Error getting AAD tokens: %s", response.status) response.raise_for_status() data = await response.json() @@ -203,12 +204,12 @@ async def sign_out( if channel_id: params["channelId"] = channel_id - logger.info(f"Signing out user {user_id} with params: {params}") + logger.info("Signing out user %s with params: %s", user_id, params) async with self.client.delete( "api/usertoken/SignOut", params=params ) as response: - if response.status >= 400 and response.status != 204: - logger.error(f"Error signing out: {response.status}") + if response.status >= 300: + logger.error("Error signing out: %s", response.status) response.raise_for_status() async def get_token_status( @@ -224,12 +225,12 @@ async def get_token_status( if include: params["include"] = include - logger.info(f"Getting token status for user {user_id} with params: {params}") + logger.info("Getting token status for user %s with params: %s", user_id, params) async with self.client.get( "api/usertoken/GetTokenStatus", params=params ) as response: - if response.status >= 400: - logger.error(f"Error getting token status: {response.status}") + if response.status >= 300: + logger.error("Error getting token status: %s", response.status) response.raise_for_status() data = await response.json() @@ -248,12 +249,14 @@ async def exchange_token( "channelId": channel_id, } - logger.info(f"Exchanging token with params: {params} and body: {body}") + logger.info("Exchanging token with params: %s and body: %s", params, body) async with self.client.post( "api/usertoken/exchange", params=params, json=body ) as response: - if response.status >= 400 and response.status != 404: - logger.error(f"Error exchanging token: {response.status}") + if response.status == 404: + return TokenResponse() + if response.status >= 300: + logger.error("Error exchanging token: %s", response.status) response.raise_for_status() data = await response.json() @@ -289,7 +292,9 @@ def __init__(self, endpoint: str, token: str, *, session: ClientSession = None): headers=headers, ) logger.debug( - f"Creating UserTokenClient with endpoint: {endpoint} and headers: {headers}" + "Creating UserTokenClient with endpoint: %s and headers: %s", + endpoint, + headers, ) if len(token) > 1: From b6fbc589832deb3d9a92fff7481e2d583ccf73aa Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Thu, 23 Oct 2025 09:50:20 -0700 Subject: [PATCH 2/5] Using lazy string formatting for logs --- .../core/connector/client/connector_client.py | 73 +++++++++++++------ .../connector/client/user_token_client.py | 5 +- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index 1a17386d..f0299c27 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -74,11 +74,13 @@ async def get_attachment_info(self, attachment_id: str) -> AttachmentInfo: url = f"v3/attachments/{attachment_id}" - logger.info(f"Getting attachment info for ID: {attachment_id}") + logger.info("Getting attachment info for ID: %s", attachment_id) async with self.client.get(url) as response: if response.status >= 300: logger.error( - f"Error getting attachment info: {response.status}", stack_info=True + "Error getting attachment info: %s", + response.status, + stack_info=True, ) response.raise_for_status() @@ -108,11 +110,13 @@ async def get_attachment(self, attachment_id: str, view_id: str) -> BytesIO: url = f"v3/attachments/{attachment_id}/views/{view_id}" - logger.info(f"Getting attachment for ID: {attachment_id}, View ID: {view_id}") + logger.info( + "Getting attachment for ID: %s, View ID: %s", attachment_id, view_id + ) async with self.client.get(url) as response: if response.status >= 300: logger.error( - f"Error getting attachment: {response.status}", stack_info=True + "Error getting attachment: %s", response.status, stack_info=True ) response.raise_for_status() @@ -143,12 +147,12 @@ async def get_conversations( ) logger.info( - f"Getting conversations with continuation token: {continuation_token}" + "Getting conversations with continuation token: %s", continuation_token ) async with self.client.get("v3/conversations", params=params) as response: if response.status >= 300: logger.error( - f"Error getting conversations: {response.status}", stack_info=True + "Error getting conversations: %s", response.status, stack_info=True ) response.raise_for_status() @@ -172,7 +176,7 @@ async def create_conversation( ) as response: if response.status not in [200, 201, 202]: logger.error( - f"Error creating conversation: {response.status}", stack_info=True + "Error creating conversation: %s", response.status, stack_info=True ) response.raise_for_status() @@ -201,7 +205,10 @@ async def reply_to_activity( url = f"v3/conversations/{conversation_id}/activities/{activity_id}" logger.info( - f"Replying to activity: {activity_id} in conversation: {conversation_id}. Activity type is {body.type}" + "Replying to activity: %s in conversation: %s. Activity type is %s", + activity_id, + conversation_id, + body.type, ) async with self.client.post( @@ -214,7 +221,8 @@ async def reply_to_activity( if response.status not in [200, 201, 202]: logger.error( - f"Error replying to activity: {result or response.status}", + "Error replying to activity: %s", + result or response.status, stack_info=True, ) response.raise_for_status() @@ -246,7 +254,9 @@ async def send_to_conversation( url = f"v3/conversations/{conversation_id}/activities" logger.info( - f"Sending to conversation: {conversation_id}. Activity type is {body.type}" + "Sending to conversation: %s. Activity type is %s", + conversation_id, + body.type, ) async with self.client.post( url, @@ -254,7 +264,9 @@ async def send_to_conversation( ) as response: if response.status not in [200, 201, 202]: logger.error( - f"Error sending to conversation: {response.status}", stack_info=True + "Error sending to conversation: %s", + response.status, + stack_info=True, ) response.raise_for_status() @@ -283,7 +295,10 @@ async def update_activity( url = f"v3/conversations/{conversation_id}/activities/{activity_id}" logger.info( - f"Updating activity: {activity_id} in conversation: {conversation_id}. Activity type is {body.type}" + "Updating activity: %s in conversation: %s. Activity type is %s", + activity_id, + conversation_id, + body.type, ) async with self.client.put( url, @@ -291,7 +306,7 @@ async def update_activity( ) as response: if response.status not in [200, 201, 202]: logger.error( - f"Error updating activity: {response.status}", stack_info=True + "Error updating activity: %s", response.status, stack_info=True ) response.raise_for_status() @@ -316,12 +331,14 @@ async def delete_activity(self, conversation_id: str, activity_id: str) -> None: url = f"v3/conversations/{conversation_id}/activities/{activity_id}" logger.info( - f"Deleting activity: {activity_id} from conversation: {conversation_id}" + "Deleting activity: %s from conversation: %s", + activity_id, + conversation_id, ) async with self.client.delete(url) as response: if response.status >= 300: logger.error( - f"Error deleting activity: {response.status}", stack_info=True + "Error deleting activity: %s", response.status, stack_info=True ) response.raise_for_status() @@ -466,7 +483,7 @@ async def delete_conversation_member( async with self.client.delete(url) as response: if response.status not in [200, 204]: logger.error( - f"Error deleting conversation member: %s", + "Error deleting conversation member: %s", response.status, stack_info=True, ) @@ -493,12 +510,15 @@ async def get_activity_members( url = f"v3/conversations/{conversation_id}/activities/{activity_id}/members" logger.info( - f"Getting activity members for conversation: {conversation_id}, Activity ID: {activity_id}" + "Getting activity members for conversation: %s, Activity ID: %s", + conversation_id, + activity_id, ) async with self.client.get(url) as response: if response.status >= 300: logger.error( - f"Error getting activity members: {response.status}", + "Error getting activity members: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -537,12 +557,16 @@ async def get_conversation_paged_members( url = f"v3/conversations/{conversation_id}/pagedmembers" logger.info( - f"Getting paged members for conversation: {conversation_id}, Page Size: {page_size}, Continuation Token: {continuation_token}" + "Getting paged members for conversation: %s, Page Size: %s, Continuation Token: %s", + conversation_id, + page_size, + continuation_token, ) async with self.client.get(url, params=params) as response: if response.status >= 300: logger.error( - f"Error getting conversation paged members: {response.status}", + "Error getting conversation paged members: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -570,11 +594,12 @@ async def send_conversation_history( conversation_id = self._normalize_conversation_id(conversation_id) url = f"v3/conversations/{conversation_id}/activities/history" - logger.info(f"Sending conversation history to conversation: {conversation_id}") + logger.info("Sending conversation history to conversation: %s", conversation_id) async with self.client.post(url, json=body) as response: if response.status not in [200, 201, 202]: logger.error( - f"Error sending conversation history: {response.status}", + "Error sending conversation history: %s", + response.status, stack_info=True, ) response.raise_for_status() @@ -609,7 +634,9 @@ def __init__(self, endpoint: str, token: str, *, session: ClientSession = None): headers=headers, ) logger.debug( - f"ConnectorClient initialized with endpoint: {endpoint} and headers: {headers}" + "ConnectorClient initialized with endpoint: %s and headers: %s", + endpoint, + headers, ) if len(token) > 1: diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py index c8e933f7..647aa1e2 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py @@ -53,13 +53,14 @@ async def get_sign_in_url( params["finalRedirect"] = final_redirect logger.info( - f"AgentSignIn.get_sign_in_url(): Getting sign-in URL with params: {params}" + "AgentSignIn.get_sign_in_url(): Getting sign-in URL with params: %s", + params, ) async with self.client.get( "api/agentsignin/getSignInUrl", params=params ) as response: if response.status >= 300: - logger.error(f"Error getting sign-in URL: {response.status}") + logger.error("Error getting sign-in URL: %s", response.status) response.raise_for_status() return await response.text() From 44c4cea0455359bc1cae55fdf144c6cc637d86e1 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Mon, 27 Oct 2025 08:29:30 -0700 Subject: [PATCH 3/5] Adding DeferredString comments --- .../activity/_utils/_deferred_string.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py b/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py index 39eb10ad..494515c3 100644 --- a/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py +++ b/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py @@ -2,12 +2,26 @@ # Licensed under the MIT License. import logging +from typing import Callable logger = logging.getLogger(__name__) class _DeferredString: - def __init__(self, func, *args, **kwargs): + """A wrapper around a function to allow for deferred evaluation. + + The result of the function is converted to a string with str(). + If an error occurs during evaluation, an error is logged and a default + string is returned. + """ + + def __init__(self, func: Callable, *args, **kwargs): + """Initializes a DeferredString instance. + + :param func: The function to be called to get the string value. + :param args: Positional arguments to pass to the function. + :param kwargs: Keyword arguments to pass to the function. + """ self.func = func self.args = args self.kwargs = kwargs From a6d3947a4a6c08ecafe5512ce237fa94703ccf50 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Mon, 27 Oct 2025 08:34:14 -0700 Subject: [PATCH 4/5] Adding warning logs to 404 cases --- .../activity/_utils/_deferred_string.py | 4 ++-- .../hosting/core/app/state/state.py | 2 +- .../core/connector/client/connector_client.py | 16 ++++++++-------- .../core/connector/client/user_token_client.py | 2 ++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py b/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py index 494515c3..d2f7e475 100644 --- a/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py +++ b/libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_deferred_string.py @@ -9,7 +9,7 @@ class _DeferredString: """A wrapper around a function to allow for deferred evaluation. - + The result of the function is converted to a string with str(). If an error occurs during evaluation, an error is logged and a default string is returned. @@ -17,7 +17,7 @@ class _DeferredString: def __init__(self, func: Callable, *args, **kwargs): """Initializes a DeferredString instance. - + :param func: The function to be called to get the string value. :param args: Positional arguments to pass to the function. :param kwargs: Keyword arguments to pass to the function. diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/state.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/state.py index 0b64406c..ce4c7064 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/state.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/state.py @@ -109,7 +109,7 @@ async def save( data = self.copy() del data["__key__"] - logger.info(f"Saving state {self.__key__}") + logger.info("Saving state %s", self.__key__) await storage.delete(self.__deleted__) await storage.write( { diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py index f0299c27..fe4b0423 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py @@ -174,7 +174,7 @@ async def create_conversation( "v3/conversations", json=body.model_dump(by_alias=True, exclude_unset=True, mode="json"), ) as response: - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error creating conversation: %s", response.status, stack_info=True ) @@ -219,7 +219,7 @@ async def reply_to_activity( ) as response: result = await response.json() if response.content_length else {} - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error replying to activity: %s", result or response.status, @@ -228,7 +228,7 @@ async def reply_to_activity( response.raise_for_status() logger.info( - f"Reply to conversation/activity: {result.get('id')}, {activity_id}" + "Reply to conversation/activity: %s, %s", result.get("id"), activity_id ) return ResourceResponse.model_validate(result) @@ -262,7 +262,7 @@ async def send_to_conversation( url, json=body.model_dump(by_alias=True, exclude_unset=True, mode="json"), ) as response: - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error sending to conversation: %s", response.status, @@ -304,7 +304,7 @@ async def update_activity( url, json=body.model_dump(by_alias=True, exclude_unset=True), ) as response: - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error updating activity: %s", response.status, stack_info=True ) @@ -376,7 +376,7 @@ async def upload_attachment( body.name, ) async with self.client.post(url, json=attachment_dict) as response: - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error uploading attachment: %s", response.status, stack_info=True ) @@ -481,7 +481,7 @@ async def delete_conversation_member( conversation_id, ) async with self.client.delete(url) as response: - if response.status not in [200, 204]: + if response.status >= 300: logger.error( "Error deleting conversation member: %s", response.status, @@ -596,7 +596,7 @@ async def send_conversation_history( logger.info("Sending conversation history to conversation: %s", conversation_id) async with self.client.post(url, json=body) as response: - if response.status not in [200, 201, 202]: + if response.status >= 300: logger.error( "Error sending conversation history: %s", response.status, diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py index 647aa1e2..90034dd2 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py @@ -127,6 +127,7 @@ async def get_token( logger.info("User_token.get_token(): Getting token with params: %s", params) async with self.client.get("api/usertoken/GetToken", params=params) as response: if response.status == 404: + logger.warning("Token not found for params: %s", params) return TokenResponse() if response.status >= 300: logger.error("Error getting token: %s", response.status) @@ -255,6 +256,7 @@ async def exchange_token( "api/usertoken/exchange", params=params, json=body ) as response: if response.status == 404: + logger.warning("Token not found for params: %s", params) return TokenResponse() if response.status >= 300: logger.error("Error exchanging token: %s", response.status) From 18d65d63d36a92c7445de476e5d03b30e0f01d90 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Mon, 27 Oct 2025 12:29:26 -0700 Subject: [PATCH 5/5] Removing special cases for 404 on exchange_token and other call --- .../hosting/core/connector/client/user_token_client.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py index 90034dd2..f19618c6 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py @@ -126,9 +126,6 @@ async def get_token( logger.info("User_token.get_token(): Getting token with params: %s", params) async with self.client.get("api/usertoken/GetToken", params=params) as response: - if response.status == 404: - logger.warning("Token not found for params: %s", params) - return TokenResponse() if response.status >= 300: logger.error("Error getting token: %s", response.status) response.raise_for_status() @@ -255,9 +252,6 @@ async def exchange_token( async with self.client.post( "api/usertoken/exchange", params=params, json=body ) as response: - if response.status == 404: - logger.warning("Token not found for params: %s", params) - return TokenResponse() if response.status >= 300: logger.error("Error exchanging token: %s", response.status) response.raise_for_status()