forked from LBRYCommunity/lbry-sdk
raise unauthorized error when cannot connect to lbrycrd
This commit is contained in:
parent
a802d1f686
commit
3315175d1c
4 changed files with 21 additions and 3 deletions
|
@ -15,7 +15,7 @@ import zmq.asyncio
|
||||||
|
|
||||||
from lbry.conf import Config
|
from lbry.conf import Config
|
||||||
from lbry.event import EventController
|
from lbry.event import EventController
|
||||||
from lbry.error import LbrycrdEventSubscriptionError
|
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
|
||||||
|
|
||||||
from .database import BlockchainDB
|
from .database import BlockchainDB
|
||||||
from .ledger import Ledger, RegTestLedger
|
from .ledger import Ledger, RegTestLedger
|
||||||
|
@ -248,6 +248,8 @@ class Lbrycrd:
|
||||||
"params": params or []
|
"params": params or []
|
||||||
}
|
}
|
||||||
async with self.session.post(self.rpc_url, json=message) as resp:
|
async with self.session.post(self.rpc_url, json=message) as resp:
|
||||||
|
if resp.status == 401:
|
||||||
|
raise LbrycrdUnauthorizedError()
|
||||||
try:
|
try:
|
||||||
result = await resp.json()
|
result = await resp.json()
|
||||||
except aiohttp.ContentTypeError as e:
|
except aiohttp.ContentTypeError as e:
|
||||||
|
|
|
@ -82,4 +82,5 @@ Code | Name | Message
|
||||||
702 | CurrencyConversion | {message}
|
702 | CurrencyConversion | {message}
|
||||||
703 | InvalidCurrency | Invalid currency: {currency} is not a supported currency.
|
703 | InvalidCurrency | Invalid currency: {currency} is not a supported currency.
|
||||||
**8xx** | Lbrycrd | **Lbrycrd**
|
**8xx** | Lbrycrd | **Lbrycrd**
|
||||||
|
801 | LbrycrdUnauthorized | Failed to authenticate with lbrycrd. Perhaps wrong username or password?
|
||||||
811 | LbrycrdEventSubscription | Lbrycrd is not publishing '{event}' events.
|
811 | LbrycrdEventSubscription | Lbrycrd is not publishing '{event}' events.
|
||||||
|
|
|
@ -406,6 +406,12 @@ class LbrycrdError(BaseError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class LbrycrdUnauthorizedError(LbrycrdError):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("Failed to authenticate with lbrycrd. Perhaps wrong username or password?")
|
||||||
|
|
||||||
|
|
||||||
class LbrycrdEventSubscriptionError(LbrycrdError):
|
class LbrycrdEventSubscriptionError(LbrycrdError):
|
||||||
|
|
||||||
def __init__(self, event):
|
def __init__(self, event):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input
|
||||||
from lbry.crypto.base58 import Base58
|
from lbry.crypto.base58 import Base58
|
||||||
from lbry.schema.claim import Stream, Channel
|
from lbry.schema.claim import Stream, Channel
|
||||||
from lbry.schema.support import Support
|
from lbry.schema.support import Support
|
||||||
from lbry.error import LbrycrdEventSubscriptionError
|
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
|
||||||
from lbry.blockchain.lbrycrd import Lbrycrd
|
from lbry.blockchain.lbrycrd import Lbrycrd
|
||||||
from lbry.blockchain.sync import BlockchainSync
|
from lbry.blockchain.sync import BlockchainSync
|
||||||
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
||||||
|
@ -284,7 +284,16 @@ class SyncingBlockchainTestCase(BasicBlockchainTestCase):
|
||||||
self.assertEqual(accepted or [], await self.get_accepted())
|
self.assertEqual(accepted or [], await self.get_accepted())
|
||||||
|
|
||||||
|
|
||||||
class TestLbrycrdEvents(AsyncioTestCase):
|
class TestLbrycrdAPIs(AsyncioTestCase):
|
||||||
|
|
||||||
|
async def test_unauthorized(self):
|
||||||
|
chain = Lbrycrd.temp_regtest()
|
||||||
|
await chain.ensure()
|
||||||
|
await chain.start()
|
||||||
|
await chain.get_new_address()
|
||||||
|
chain.conf.set(lbrycrd_rpc_pass='wrong')
|
||||||
|
with self.assertRaises(LbrycrdUnauthorizedError):
|
||||||
|
await chain.get_new_address()
|
||||||
|
|
||||||
async def test_zmq(self):
|
async def test_zmq(self):
|
||||||
chain = Lbrycrd.temp_regtest()
|
chain = Lbrycrd.temp_regtest()
|
||||||
|
|
Loading…
Reference in a new issue