From 2cfd29564bb32a1cc753bc7a74aa4abe13f12e03 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 9 Jun 2017 13:39:55 -0400 Subject: [PATCH] add resolution exception types --- lbrynet/core/Error.py | 12 ++++++++++++ lbrynet/core/Wallet.py | 16 ++++++++++++---- lbrynet/lbrynet_daemon/Daemon.py | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lbrynet/core/Error.py b/lbrynet/core/Error.py index 077b4c88c..139cd5bdf 100644 --- a/lbrynet/core/Error.py +++ b/lbrynet/core/Error.py @@ -39,6 +39,18 @@ class UnknownNameError(Exception): self.name = name +class UnknownClaimID(Exception): + def __init__(self, claim_id): + Exception.__init__(self, 'Claim {} is unknown'.format(claim_id)) + self.claim_id = claim_id + + +class UnknownURI(Exception): + def __init__(self, uri): + Exception.__init__(self, 'URI {} cannot be resolved'.format(uri)) + self.name = uri + + class InvalidName(Exception): def __init__(self, name, invalid_characters): self.name = name diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index f1e1947fc..793a9fd5c 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -26,6 +26,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet from lbrynet.core.client.ClientRequest import ClientRequest from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError +from lbrynet.core.Error import UnknownClaimID, UnknownURI log = logging.getLogger(__name__) @@ -702,9 +703,13 @@ class Wallet(object): if 'error' in results: if results['error'] in ['name is not claimed', 'claim not found']: - raise UnknownNameError(results['error']) - else: - raise Exception(results['error']) + if 'claim_id' in results: + raise UnknownClaimID(results['claim_id']) + elif 'name' in results: + raise UnknownNameError(results['name']) + elif 'uri' in results: + raise UnknownURI(results['uri']) + raise Exception(results['error']) if 'certificate' in results: try: @@ -832,7 +837,10 @@ class Wallet(object): cached_claim = None if not cached_claim: claim = yield self._get_claim_by_outpoint(txid, nout) - result = yield self._handle_claim_result(claim) + try: + result = yield self._handle_claim_result(claim) + except (UnknownNameError, UnknownClaimID, UnknownURI) as err: + result = {'error': err.message} else: result = cached_claim defer.returnValue(result) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 84ee355ee..b0258aa11 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -46,7 +46,7 @@ from lbrynet.core.looping_call_manager import LoopingCallManager from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash -from lbrynet.core.Error import NoSuchStreamHash +from lbrynet.core.Error import NoSuchStreamHash, UnknownClaimID, UnknownURI log = logging.getLogger(__name__) @@ -1326,7 +1326,7 @@ class Daemon(AuthJSONRPCServer): else: claim_results = yield self.session.wallet.get_claim_by_name(name) result = format_json_out_amount_as_float(claim_results) - except (TypeError, UnknownNameError): + except (TypeError, UnknownNameError, UnknownClaimID, UnknownURI): result = False response = yield self._render_response(result) defer.returnValue(response)