mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 10:15:20 +00:00
labels: don't dump trace if failed to connect to server
This commit is contained in:
parent
c23e949848
commit
8c3ab63504
1 changed files with 21 additions and 2 deletions
|
@ -3,6 +3,7 @@ import hashlib
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
@ -13,6 +14,18 @@ from electrum.util import log_exceptions, ignore_exceptions, make_aiohttp_sessio
|
||||||
from electrum.network import Network
|
from electrum.network import Network
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorConnectingServer(Exception):
|
||||||
|
def __init__(self, reason: Union[str, Exception] = None):
|
||||||
|
self.reason = reason
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
header = _("Error connecting to {} server").format('Labels')
|
||||||
|
reason = self.reason
|
||||||
|
if isinstance(reason, BaseException):
|
||||||
|
reason = repr(reason)
|
||||||
|
return f"{header}: {reason}" if reason else header
|
||||||
|
|
||||||
|
|
||||||
class LabelsPlugin(BasePlugin):
|
class LabelsPlugin(BasePlugin):
|
||||||
|
|
||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config, name):
|
||||||
|
@ -109,7 +122,10 @@ class LabelsPlugin(BasePlugin):
|
||||||
wallet_id = wallet_data[2]
|
wallet_id = wallet_data[2]
|
||||||
nonce = 1 if force else self.get_nonce(wallet) - 1
|
nonce = 1 if force else self.get_nonce(wallet) - 1
|
||||||
self.print_error("asking for labels since nonce", nonce)
|
self.print_error("asking for labels since nonce", nonce)
|
||||||
response = await self.do_get("/labels/since/%d/for/%s" % (nonce, wallet_id))
|
try:
|
||||||
|
response = await self.do_get("/labels/since/%d/for/%s" % (nonce, wallet_id))
|
||||||
|
except Exception as e:
|
||||||
|
raise ErrorConnectingServer(e) from e
|
||||||
if response["labels"] is None:
|
if response["labels"] is None:
|
||||||
self.print_error('no new labels')
|
self.print_error('no new labels')
|
||||||
return
|
return
|
||||||
|
@ -141,7 +157,10 @@ class LabelsPlugin(BasePlugin):
|
||||||
@ignore_exceptions
|
@ignore_exceptions
|
||||||
@log_exceptions
|
@log_exceptions
|
||||||
async def pull_safe_thread(self, wallet, force):
|
async def pull_safe_thread(self, wallet, force):
|
||||||
await self.pull_thread(wallet, force)
|
try:
|
||||||
|
await self.pull_thread(wallet, force)
|
||||||
|
except ErrorConnectingServer as e:
|
||||||
|
self.print_error(str(e))
|
||||||
|
|
||||||
def pull(self, wallet, force):
|
def pull(self, wallet, force):
|
||||||
if not wallet.network: raise Exception(_('You are offline.'))
|
if not wallet.network: raise Exception(_('You are offline.'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue