forked from LBRYCommunity/lbry-sdk
return api errors from wallet_add
and wallet_create
This commit is contained in:
parent
d07685f0e9
commit
25d54accf8
3 changed files with 29 additions and 5 deletions
|
@ -62,6 +62,9 @@ Code | Name | Message
|
|||
432 | ServerPaymentWalletLocked | Cannot spend funds with locked wallet, skipping payment round.
|
||||
433 | ServerPaymentFeeAboveMaxAllowed | Daily server fee of {daily_fee} exceeds maximum configured of {max_fee} LBC.
|
||||
434 | WalletNotLoaded | Wallet {wallet_id} is not loaded.
|
||||
435 | WalletAlreadyLoaded | Wallet {wallet_path} is already loaded.
|
||||
436 | WalletNotFound | Wallet not found at {wallet_path}.
|
||||
437 | WalletAlreadyExists | Wallet {wallet_path} already exists, use `wallet_add` to load it.
|
||||
**5xx** | Blob | **Blobs**
|
||||
500 | BlobNotFound | Blob not found.
|
||||
501 | BlobPermissionDenied | Permission denied to read blob.
|
||||
|
|
|
@ -278,6 +278,27 @@ class WalletNotLoadedError(WalletError):
|
|||
super().__init__(f"Wallet {wallet_id} is not loaded.")
|
||||
|
||||
|
||||
class WalletAlreadyLoadedError(WalletError):
|
||||
|
||||
def __init__(self, wallet_path):
|
||||
self.wallet_path = wallet_path
|
||||
super().__init__(f"Wallet {wallet_path} is already loaded.")
|
||||
|
||||
|
||||
class WalletNotFoundError(WalletError):
|
||||
|
||||
def __init__(self, wallet_path):
|
||||
self.wallet_path = wallet_path
|
||||
super().__init__(f"Wallet not found at {wallet_path}.")
|
||||
|
||||
|
||||
class WalletAlreadyExistsError(WalletError):
|
||||
|
||||
def __init__(self, wallet_path):
|
||||
self.wallet_path = wallet_path
|
||||
super().__init__(f"Wallet {wallet_path} already exists, use `wallet_add` to load it.")
|
||||
|
||||
|
||||
class BlobError(BaseError):
|
||||
"""
|
||||
**Blobs**
|
||||
|
|
|
@ -36,7 +36,7 @@ from lbry.blob_exchange.downloader import download_blob
|
|||
from lbry.dht.peer import make_kademlia_peer
|
||||
from lbry.error import (
|
||||
DownloadSDTimeoutError, ComponentsNotStartedError, ComponentStartConditionNotMetError,
|
||||
CommandDoesNotExistError, BaseError
|
||||
CommandDoesNotExistError, BaseError, WalletNotFoundError, WalletAlreadyLoadedError, WalletAlreadyExistsError
|
||||
)
|
||||
from lbry.extras import system_info
|
||||
from lbry.extras.daemon import analytics
|
||||
|
@ -1276,9 +1276,9 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
wallet_path = os.path.join(self.conf.wallet_dir, 'wallets', wallet_id)
|
||||
for wallet in self.wallet_manager.wallets:
|
||||
if wallet.id == wallet_id:
|
||||
raise Exception(f"Wallet at path '{wallet_path}' already exists and is loaded.")
|
||||
raise WalletAlreadyLoadedError(wallet_path)
|
||||
if os.path.exists(wallet_path):
|
||||
raise Exception(f"Wallet at path '{wallet_path}' already exists, use 'wallet_add' to load wallet.")
|
||||
raise WalletAlreadyExistsError(wallet_path)
|
||||
|
||||
wallet = self.wallet_manager.import_wallet(wallet_path)
|
||||
if not wallet.accounts and create_account:
|
||||
|
@ -1311,9 +1311,9 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
wallet_path = os.path.join(self.conf.wallet_dir, 'wallets', wallet_id)
|
||||
for wallet in self.wallet_manager.wallets:
|
||||
if wallet.id == wallet_id:
|
||||
raise Exception(f"Wallet at path '{wallet_path}' is already loaded.")
|
||||
raise WalletAlreadyLoadedError(wallet_path)
|
||||
if not os.path.exists(wallet_path):
|
||||
raise Exception(f"Wallet at path '{wallet_path}' was not found.")
|
||||
raise WalletNotFoundError(wallet_path)
|
||||
wallet = self.wallet_manager.import_wallet(wallet_path)
|
||||
if self.ledger.network.is_connected:
|
||||
for account in wallet.accounts:
|
||||
|
|
Loading…
Reference in a new issue