forked from LBRYCommunity/lbry-sdk
add resolution exception types
This commit is contained in:
parent
b85655ff58
commit
2cfd29564b
3 changed files with 26 additions and 6 deletions
|
@ -39,6 +39,18 @@ class UnknownNameError(Exception):
|
||||||
self.name = name
|
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):
|
class InvalidName(Exception):
|
||||||
def __init__(self, name, invalid_characters):
|
def __init__(self, name, invalid_characters):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
|
@ -26,6 +26,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
|
||||||
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
|
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
|
||||||
from lbrynet.core.client.ClientRequest import ClientRequest
|
from lbrynet.core.client.ClientRequest import ClientRequest
|
||||||
from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError
|
from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError
|
||||||
|
from lbrynet.core.Error import UnknownClaimID, UnknownURI
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -702,8 +703,12 @@ class Wallet(object):
|
||||||
|
|
||||||
if 'error' in results:
|
if 'error' in results:
|
||||||
if results['error'] in ['name is not claimed', 'claim not found']:
|
if results['error'] in ['name is not claimed', 'claim not found']:
|
||||||
raise UnknownNameError(results['error'])
|
if 'claim_id' in results:
|
||||||
else:
|
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'])
|
raise Exception(results['error'])
|
||||||
|
|
||||||
if 'certificate' in results:
|
if 'certificate' in results:
|
||||||
|
@ -832,7 +837,10 @@ class Wallet(object):
|
||||||
cached_claim = None
|
cached_claim = None
|
||||||
if not cached_claim:
|
if not cached_claim:
|
||||||
claim = yield self._get_claim_by_outpoint(txid, nout)
|
claim = yield self._get_claim_by_outpoint(txid, nout)
|
||||||
|
try:
|
||||||
result = yield self._handle_claim_result(claim)
|
result = yield self._handle_claim_result(claim)
|
||||||
|
except (UnknownNameError, UnknownClaimID, UnknownURI) as err:
|
||||||
|
result = {'error': err.message}
|
||||||
else:
|
else:
|
||||||
result = cached_claim
|
result = cached_claim
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
|
@ -46,7 +46,7 @@ from lbrynet.core.looping_call_manager import LoopingCallManager
|
||||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||||
from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -1326,7 +1326,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
else:
|
else:
|
||||||
claim_results = yield self.session.wallet.get_claim_by_name(name)
|
claim_results = yield self.session.wallet.get_claim_by_name(name)
|
||||||
result = format_json_out_amount_as_float(claim_results)
|
result = format_json_out_amount_as_float(claim_results)
|
||||||
except (TypeError, UnknownNameError):
|
except (TypeError, UnknownNameError, UnknownClaimID, UnknownURI):
|
||||||
result = False
|
result = False
|
||||||
response = yield self._render_response(result)
|
response = yield self._render_response(result)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
Loading…
Reference in a new issue