-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Any, Dict, Optional, Protocol | ||
|
||
from multiversx_sdk_network_providers import GenericError, ProxyNetworkProvider | ||
Check failure on line 3 in multiversx_sdk_cli/custom_network_provider.py GitHub Actions / runner / mypy
|
||
|
||
from multiversx_sdk_cli.errors import ProxyError | ||
from multiversx_sdk_cli.interfaces import ISimulateResponse, ITransaction | ||
|
||
|
||
class ITransactionOnNetwork(Protocol): | ||
hash: str | ||
is_completed: Optional[bool] | ||
|
||
def to_dictionary(self) -> Dict[str, Any]: | ||
... | ||
|
||
|
||
class CustomNetworkProvider: | ||
def __init__(self, url: str) -> None: | ||
self._provider = ProxyNetworkProvider(url) | ||
|
||
def send_transaction(self, transaction: ITransaction) -> str: | ||
try: | ||
hash = self._provider.send_transaction(transaction) | ||
return hash | ||
Check failure on line 24 in multiversx_sdk_cli/custom_network_provider.py GitHub Actions / runner / mypy
|
||
except GenericError as ge: | ||
url = ge.url | ||
message = ge.data.get("error", "") | ||
data = ge.data.get("data", "") | ||
code = ge.data.get("code", "") | ||
raise ProxyError(message, url, data, code) | ||
|
||
def get_transaction(self, tx_hash: str, with_process_status: Optional[bool] = False) -> ITransactionOnNetwork: | ||
return self._provider.get_transaction(tx_hash, with_process_status) | ||
Check failure on line 33 in multiversx_sdk_cli/custom_network_provider.py GitHub Actions / runner / mypy
|
||
|
||
def simulate_transaction(self, transaction: ITransaction) -> ISimulateResponse: | ||
return self._provider.simulate_transaction(transaction) | ||
Check failure on line 36 in multiversx_sdk_cli/custom_network_provider.py GitHub Actions / runner / mypy
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
def __init__(self, message: str, url: str, data: str, code: str): | ||
inner = { | ||
"url": url, | ||
"data": data, | ||
"code": code | ||
} | ||
super().__init__(message, inner) |
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.