diff --git a/aries_cloudagent/config/ledger.py b/aries_cloudagent/config/ledger.py index d747941378..021a8f51aa 100644 --- a/aries_cloudagent/config/ledger.py +++ b/aries_cloudagent/config/ledger.py @@ -11,7 +11,7 @@ from prompt_toolkit.formatted_text import HTML from ..ledger.base import BaseLedger -from ..transport.util import http_fetch, TransportFetchError +from ..utils.http import fetch, FetchError from .base import ConfigError from .injection_context import InjectionContext @@ -25,8 +25,8 @@ async def fetch_genesis_transactions(genesis_url: str) -> str: headers["Content-Type"] = "application/json" LOGGER.info("Fetching genesis transactions from: %s", genesis_url) try: - return await http_fetch(genesis_url, headers=headers) - except TransportFetchError as e: + return await fetch(genesis_url, headers=headers) + except FetchError as e: raise ConfigError("Error retrieving ledger genesis transactions") from e diff --git a/aries_cloudagent/transport/util.py b/aries_cloudagent/utils/http.py similarity index 87% rename from aries_cloudagent/transport/util.py rename to aries_cloudagent/utils/http.py index 1a89ba7d02..a32b17c17a 100644 --- a/aries_cloudagent/transport/util.py +++ b/aries_cloudagent/utils/http.py @@ -1,19 +1,19 @@ -"""Transport utility methods.""" +"""HTTP utility methods.""" import asyncio from aiohttp import BaseConnector, ClientError, ClientResponse, ClientSession -from ..messaging.repeat import RepeatSequence +from ..core.error import BaseError -from .error import TransportError +from .repeat import RepeatSequence -class TransportFetchError(TransportError): +class FetchError(BaseError): """Error raised when an HTTP fetch fails.""" -async def http_fetch( +async def fetch( url: str, *, headers: dict = None, @@ -56,4 +56,4 @@ async def http_fetch( return await (response.json() if json else response.text()) except (ClientError, asyncio.TimeoutError) as e: if attempt.final: - raise TransportFetchError("Exceeded maximum fetch attempts") from e + raise FetchError("Exceeded maximum fetch attempts") from e diff --git a/aries_cloudagent/messaging/repeat.py b/aries_cloudagent/utils/repeat.py similarity index 100% rename from aries_cloudagent/messaging/repeat.py rename to aries_cloudagent/utils/repeat.py diff --git a/aries_cloudagent/transport/tests/test_util.py b/aries_cloudagent/utils/tests/test_http.py similarity index 82% rename from aries_cloudagent/transport/tests/test_util.py rename to aries_cloudagent/utils/tests/test_http.py index 7d7557fdec..a9b486fb5d 100644 --- a/aries_cloudagent/transport/tests/test_util.py +++ b/aries_cloudagent/utils/tests/test_http.py @@ -1,7 +1,7 @@ from aiohttp import web from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop -from ..util import http_fetch, TransportFetchError +from ..http import fetch, FetchError class TestTransportUtils(AioHTTPTestCase): @@ -26,19 +26,19 @@ async def succeed_route(self, request): return ret @unittest_run_loop - async def test_http_fetch(self): + async def test_fetch(self): server_addr = f"http://localhost:{self.server.port}" - result = await http_fetch( + result = await fetch( f"{server_addr}/succeed", session=self.client.session, json=True ) assert result == [1] assert self.succeed_calls == 1 @unittest_run_loop - async def test_http_fetch_fail(self): + async def test_fetch_fail(self): server_addr = f"http://localhost:{self.server.port}" - with self.assertRaises(TransportFetchError): - result = await http_fetch( + with self.assertRaises(FetchError): + result = await fetch( f"{server_addr}/fail", max_attempts=2, interval=0, diff --git a/aries_cloudagent/messaging/tests/test_repeat.py b/aries_cloudagent/utils/tests/test_repeat.py similarity index 100% rename from aries_cloudagent/messaging/tests/test_repeat.py rename to aries_cloudagent/utils/tests/test_repeat.py