Skip to content
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

add better error handling for invalid client URLs #388

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [[Unreleased]]
### Added:
- Support for dynamic fee calculation
- Better error handling for invalid client URL

### Fixed
- Resolve `txnNotFound` error with `send_reliable_submission` when waiting for a submitted malformed transaction
Expand Down
Empty file added tests/unit/clients/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/unit/clients/test_json_rpc_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test the json_rpc_client."""
from __future__ import annotations

from unittest import TestCase
from xrpl.asyncio.clients.exceptions import XRPLRequestFailureException

from xrpl.clients import JsonRpcClient
from xrpl.models.requests import ServerInfo


class TestJsonRpcClient(TestCase):
"""Test json_rpc_client."""

def test_json_rpc_client_valid_url(self: TestJsonRpcClient) -> None:
# Valid URL
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
client = JsonRpcClient(JSON_RPC_URL)
client.request(ServerInfo())
khancode marked this conversation as resolved.
Show resolved Hide resolved

def test_json_rpc_client_invalid_url(self: TestJsonRpcClient) -> None:
# Invalid URL
JSON_RPC_URL = "https://s2.ripple.com:51233/"
with self.assertRaises(XRPLRequestFailureException):
client = JsonRpcClient(JSON_RPC_URL)
client.request(ServerInfo())

6 changes: 6 additions & 0 deletions xrpl/asyncio/clients/json_rpc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing_extensions import Final

from xrpl.asyncio.clients.client import Client
from xrpl.asyncio.clients.exceptions import XRPLRequestFailureException
from xrpl.asyncio.clients.utils import json_to_response, request_to_json_rpc
from xrpl.models.requests.request import Request
from xrpl.models.response import Response
Expand Down Expand Up @@ -36,4 +37,9 @@ async def request_impl(self: JsonRpcBase, request: Request) -> Response:
self.url,
json=request_to_json_rpc(request),
)
if response.status_code != 200:
khancode marked this conversation as resolved.
Show resolved Hide resolved
raise XRPLRequestFailureException({
'error': response.status_code,
'error_message': response.text,
})
return json_to_response(response.json())