forked from bitcoinafterlife/bal-electrum-plugin
feat(willexecutors): differentiate empty server response from network error
Raise NoServersForChainError when the welist server responds but returns no data for the requested chain, showing a chain-specific message instead of the generic network error.
This commit is contained in:
@@ -73,6 +73,10 @@ chainname = BalPlugin.chainname
|
|||||||
|
|
||||||
class Willexecutors:
|
class Willexecutors:
|
||||||
|
|
||||||
|
class NoServersForChainError(Exception):
|
||||||
|
"""Raised when the welist server responds but returns no data for the
|
||||||
|
requested chain, indicating no active servers for that network."""
|
||||||
|
|
||||||
# Expose the networking constants as class attributes so the GUI layer can
|
# Expose the networking constants as class attributes so the GUI layer can
|
||||||
# reference them (e.g. to show the "Xs / DEADLINEs" countdown) without
|
# reference them (e.g. to show the "Xs / DEADLINEs" countdown) without
|
||||||
# importing module-level names. Single source of truth: the module
|
# importing module-level names. Single source of truth: the module
|
||||||
|
|||||||
@@ -1112,6 +1112,7 @@ class BalWindow:
|
|||||||
candidates.append(url)
|
candidates.append(url)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
any_server_reached = False
|
||||||
net = Network.get_instance()
|
net = Network.get_instance()
|
||||||
_logger.info(f"fetch_will_executors_list: network present = {net is not None}")
|
_logger.info(f"fetch_will_executors_list: network present = {net is not None}")
|
||||||
for url in candidates:
|
for url in candidates:
|
||||||
@@ -1124,6 +1125,7 @@ class BalWindow:
|
|||||||
resp = Willexecutors.send_request(
|
resp = Willexecutors.send_request(
|
||||||
"get", url, timeout=10, max_retries=1, retry_sleep=1,
|
"get", url, timeout=10, max_retries=1, retry_sleep=1,
|
||||||
)
|
)
|
||||||
|
any_server_reached = True
|
||||||
_logger.info(
|
_logger.info(
|
||||||
f"fetch_will_executors_list: resp type={type(resp).__name__} "
|
f"fetch_will_executors_list: resp type={type(resp).__name__} "
|
||||||
f"len={len(resp) if hasattr(resp, '__len__') else 'n/a'}"
|
f"len={len(resp) if hasattr(resp, '__len__') else 'n/a'}"
|
||||||
@@ -1142,6 +1144,8 @@ class BalWindow:
|
|||||||
_logger.error(
|
_logger.error(
|
||||||
f"fetch_will_executors_list: {url} -> {type(e).__name__}: {e}"
|
f"fetch_will_executors_list: {url} -> {type(e).__name__}: {e}"
|
||||||
)
|
)
|
||||||
|
if not result and any_server_reached:
|
||||||
|
raise Willexecutors.NoServersForChainError(chainname)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Simple, user-facing message shown when the download fails for any reason
|
# Simple, user-facing message shown when the download fails for any reason
|
||||||
@@ -1205,7 +1209,14 @@ class BalWindow:
|
|||||||
|
|
||||||
def on_failure(exc_info):
|
def on_failure(exc_info):
|
||||||
_logger.error(f"download_list failed: {exc_info}")
|
_logger.error(f"download_list failed: {exc_info}")
|
||||||
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
if isinstance(exc_info[1], Willexecutors.NoServersForChainError):
|
||||||
|
chainname = BalPlugin.chainname
|
||||||
|
self.show_warning(_(
|
||||||
|
f"No active will-executor found for the "
|
||||||
|
f"{chainname} network."
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
||||||
|
|
||||||
self.waiting_dialog = BalWaitingDialog(
|
self.waiting_dialog = BalWaitingDialog(
|
||||||
self, base_msg, task, on_success, on_failure, exe=False
|
self, base_msg, task, on_success, on_failure, exe=False
|
||||||
|
|||||||
Reference in New Issue
Block a user