-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle proxy error #413
Handle proxy error #413
Conversation
multiversx_sdk_cli/cli_shared.py
Outdated
message = ge.data["error"] | ||
data = ge.data["data"] | ||
code = ge.data["code"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case, perhaps use ge.get("...", "")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -198,3 +198,13 @@ def __init__(self, message: str): | |||
class ArgumentsNotProvidedError(KnownError): | |||
def __init__(self, message: str): | |||
super().__init__(message) | |||
|
|||
|
|||
class ProxyError(KnownError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
multiversx_sdk_cli/transactions.py
Outdated
try: | ||
tx_hash = proxy.send_transaction(payload) | ||
except GenericError as ge: | ||
url = ge.url | ||
message = ge.data["error"] | ||
data = ge.data["data"] | ||
code = ge.data["code"] | ||
raise ProxyError(message, url, data, code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have this in several places now, perhaps use the decorator pattern, and do a custom proxy provider e.g. CustomNetworkProvider(ProxyNetworkProvider)
that overrides this function, catches & re-throws?
Alternatively, catch multiversx_sdk_network_providers.GenericError
in cli.py
, in the main function, and handle it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a CustomNetworkProvider
.
@@ -112,6 +112,7 @@ def wallet_new(args: Any): | |||
|
|||
mnemonic = Mnemonic.generate() | |||
print(f"Mnemonic: {mnemonic.get_text()}") | |||
print(f"Wallet address: {mnemonic.derive_key().generate_public_key().to_address(address_hrp).to_bech32()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully, not a breaking change for some users 🤞
People who rely on a more structured output should use the outfile
argument.
utils.dump_out_json(output, outfile=args.outfile) | ||
tx_hash = proxy.send_transaction(tx) | ||
output.set_emitted_transaction_hash(tx_hash) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try / finally was good here - so that the user sees the emitted transaction even if the send fails with exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Added.
Handle proxy error and display address of newly created wallet.
Fixes #412.