From c47de8597464e39ccdd9e5083d4f4c14e1c9c2c4 Mon Sep 17 00:00:00 2001 From: mr-rooftop <47558538+mr-rooftop@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:15:28 +0700 Subject: [PATCH] Corrected try except if seed node is unavailable (#98) --- bot/handlers/network_info.py | 4 ++-- bot/jobs.py | 7 +++---- bot/messages.py | 3 ++- bot/service/thorchain_network_service.py | 8 ++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bot/handlers/network_info.py b/bot/handlers/network_info.py index b744851..d43420e 100644 --- a/bot/handlers/network_info.py +++ b/bot/handlers/network_info.py @@ -1,7 +1,7 @@ from collections import defaultdict from helpers import * -from messages import NETWORK_ERROR_MSG +from messages import * def show_network_menu(update, context): @@ -105,7 +105,7 @@ async def show_vault_key_addresses(update, context): except Exception as e: logger.exception(e) try_message_with_home_menu(context=context, chat_id=update.effective_chat.id, - text="Can't get node addresses, please try again.") + text=NODE_LIST_UNAVAILABLE_ERROR_MSG) return monitored_node_accounts = list(filter(lambda x: x['status'] == 'active', node_accounts)) diff --git a/bot/jobs.py b/bot/jobs.py index 84a6e4d..f52681e 100644 --- a/bot/jobs.py +++ b/bot/jobs.py @@ -2,6 +2,7 @@ from service.local_storage_service import LocalStorageService from service.thorchain_network_service import * from packaging import version +from messages import * def thornode_checks(context): @@ -266,8 +267,7 @@ def check_versions_status(context): node_accounts = get_node_accounts() except Exception as e: logger.exception(e) - message = 'I couldn\'t check the versions of other nodes in network! List of nodes currently unavailable!' - try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=message) + try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=NODE_LIST_UNAVAILABLE_ERROR_MSG) return highest_version = max(map(lambda n: n['version'], node_accounts), key=lambda v: version.parse(v)) @@ -295,8 +295,7 @@ def check_churning(context): validators = get_node_accounts() except Exception as e: logger.exception(e) - message = 'I couldn\'t check the statuses of other nodes in network! List of nodes currently unavailable!' - try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=message) + try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=NODE_LIST_UNAVAILABLE_ERROR_MSG) return diff --git a/bot/messages.py b/bot/messages.py index c8edb62..b0d3845 100644 --- a/bot/messages.py +++ b/bot/messages.py @@ -1 +1,2 @@ -NETWORK_ERROR_MSG = '😱 There was an error while getting data 😱\n Please check your internet connection and try again!' +NETWORK_ERROR_MSG = '😱 There was an error while getting data 😱\nEither your internet connection or the node endpoint is down!' +NODE_LIST_UNAVAILABLE_ERROR_MSG = '😱 I couldn\'t check the versions of other nodes in network! 😱\nList of nodes currently unavailable!' \ No newline at end of file diff --git a/bot/service/thorchain_network_service.py b/bot/service/thorchain_network_service.py index 8eef116..7b3847a 100644 --- a/bot/service/thorchain_network_service.py +++ b/bot/service/thorchain_network_service.py @@ -3,7 +3,7 @@ import aiohttp import requests -from constants import DEBUG, logger, BINANCE_NODE_IP, NETWORK_TYPE, CONNECTION_TIMEOUT +from constants import * def get_node_accounts(): @@ -78,7 +78,11 @@ def get_random_seed_node_endpoint() -> str: random.shuffle(available_node_ips) response = None for node_ip in available_node_ips: - response = requests.get(url='http://' + node_ip + ':8080/v1/health', timeout=10) + try: + response = requests.get(url='http://' + node_ip + ':8080/v1/health', timeout=10) + except Exception as e: + logger.exception(e) + continue if response.status_code == 200: return node_ip raise BadStatusException(response)