Skip to content

Commit 7bde769

Browse files
Guillaume De Saint MartinGuillaumeDSM
authored andcommitted
[Devices] handle missing selected device error in copy trading
1 parent f0f2e49 commit 7bde769

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

octobot/community/authentication.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ async def _ensure_init_community_feed(self):
112112
await self._community_feed.start()
113113

114114
async def register_feed_callback(self, channel_type, callback, identifier=None):
115-
await self._ensure_init_community_feed()
116-
await self._community_feed.register_feed_callback(channel_type, callback, identifier=identifier)
115+
try:
116+
await self._ensure_init_community_feed()
117+
await self._community_feed.register_feed_callback(channel_type, callback, identifier=identifier)
118+
except errors.DeviceError as e:
119+
self.logger.error(f"Impossible to connect to community signals: {e}")
117120

118121
async def send(self, message, channel_type, identifier=None):
119122
"""
@@ -230,7 +233,7 @@ async def update_selected_device(self):
230233
self.user_account.flush_device_details()
231234
await self._load_device_if_selected()
232235
if not self.user_account.has_selected_device_data():
233-
self.logger.info("No selected device. Please select a device to enable your community features.")
236+
self.logger.info(self.user_account.NO_SELECTED_DEVICE_DESC)
234237

235238
async def _load_device_if_selected(self):
236239
# 1. use user selected device id if any

octobot/community/community_user_account.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
# You should have received a copy of the GNU General Public
1515
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
1616
import octobot.community.community_supports as community_supports
17+
import octobot.community.errors as errors
1718

1819

1920
class CommunityUserAccount:
2021
USER_DATA_CONTENT = "content"
22+
NO_SELECTED_DEVICE_DESC = "No selected device. Please select a device to enable your community features."
23+
2124

2225
def __init__(self):
2326
self.gql_user_id = None
@@ -51,7 +54,10 @@ def get_selected_device_raw_data(self):
5154
return self._selected_device_raw_data
5255

5356
def get_selected_device_uuid(self):
54-
return self.get_selected_device_raw_data().get("uuid", None)
57+
try:
58+
return self.get_selected_device_raw_data().get("uuid", None)
59+
except AttributeError:
60+
raise errors.DeviceError(self.NO_SELECTED_DEVICE_DESC)
5561

5662
@staticmethod
5763
def get_device_id(device):

0 commit comments

Comments
 (0)