diff --git a/packages/apps/src/microsoft_teams/apps/app_oauth.py b/packages/apps/src/microsoft_teams/apps/app_oauth.py index 2876d246..535eadf3 100644 --- a/packages/apps/src/microsoft_teams/apps/app_oauth.py +++ b/packages/apps/src/microsoft_teams/apps/app_oauth.py @@ -60,19 +60,25 @@ async def sign_in_token_exchange( self.event_emitter.emit("sign_in", SignInEvent(activity_ctx=ctx, token_response=token)) return None except Exception as e: - ctx.logger.error( - f"Error exchanging token for user {activity.from_.id} in " - f"conversation {activity.conversation.id}: {e}" - ) if isinstance(e, HTTPStatusError): status = e.response.status_code if status not in (404, 400, 412): + log.error( + f"Error exchanging token for user {activity.from_.id} in " + f"conversation {activity.conversation.id}: {e}" + ) self.event_emitter.emit("error", ErrorEvent(error=e, context={"activity": activity})) return InvokeResponse(status=status or 500) - ctx.logger.warning( - f"Unable to exchange token for user {activity.from_.id} in " - f"conversation {activity.conversation.id}: {e}" - ) + log.info( + f"Unable to exchange token for user {activity.from_.id} in " + f"conversation {activity.conversation.id}: {e}" + ) + else: + log.error( + f"Unable to exchange token for user {activity.from_.id} in " + f"conversation {activity.conversation.id}: {e}" + ) + self.event_emitter.emit("error", ErrorEvent(error=e, context={"activity": activity})) return InvokeResponse( status=412, body=TokenExchangeInvokeResponse( diff --git a/packages/apps/tests/test_app_oauth.py b/packages/apps/tests/test_app_oauth.py index fa4981d8..62ef79e5 100644 --- a/packages/apps/tests/test_app_oauth.py +++ b/packages/apps/tests/test_app_oauth.py @@ -168,9 +168,6 @@ async def test_sign_in_token_exchange_http_error_404(self, oauth_handlers, mock_ # Verify no error event emitted for 404 oauth_handlers.event_emitter.emit.assert_not_called() - # Verify warning logged - mock_context.logger.warning.assert_called_once() - # Verify failure response assert isinstance(result, InvokeResponse) and isinstance(result.body, TokenExchangeInvokeResponse) assert result.status == 412 @@ -215,8 +212,10 @@ async def test_sign_in_token_exchange_generic_exception( result = await oauth_handlers.sign_in_token_exchange(mock_context) - # Verify warning logged - mock_context.logger.warning.assert_called_once() + # Verify error event emitted for non-HTTP exceptions + oauth_handlers.event_emitter.emit.assert_called_once_with( + "error", ErrorEvent(error=generic_error, context={"activity": token_exchange_activity}) + ) # Verify failure response assert isinstance(result, InvokeResponse) and isinstance(result.body, TokenExchangeInvokeResponse)