diff --git a/adcm_aio_client/core/errors.py b/adcm_aio_client/core/errors.py index da598ae..1930bfc 100644 --- a/adcm_aio_client/core/errors.py +++ b/adcm_aio_client/core/errors.py @@ -15,6 +15,10 @@ class ADCMClientError(Exception): pass +class WaitTimeoutError(ADCMClientError): + pass + + # Session @@ -25,10 +29,6 @@ class ClientInitError(ADCMClientError): # Version -class VersionRetrievalError(ADCMClientError): - pass - - class NotSupportedVersionError(ADCMClientError): pass @@ -44,7 +44,7 @@ class NoCredentialsError(RequesterError): pass -class WrongCredentialsError(RequesterError): +class AuthenticationError(RequesterError): pass @@ -64,31 +64,31 @@ class ResponseDataConversionError(RequesterError): pass -class ResponseError(RequesterError): +class UnknownError(RequesterError): pass -class BadRequestError(ResponseError): +class BadRequestError(UnknownError): pass -class UnauthorizedError(ResponseError): +class UnauthorizedError(UnknownError): pass -class ForbiddenError(ResponseError): +class PermissionDeniedError(UnknownError): pass -class NotFoundError(ResponseError): +class NotFoundError(UnknownError): pass -class ConflictError(ResponseError): +class ConflictError(UnknownError): pass -class ServerError(ResponseError): +class ServerError(UnknownError): pass diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index ad03b33..a17f5e1 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -8,7 +8,7 @@ from asyncstdlib.functools import cached_property as async_cached_property # noqa: N813 from adcm_aio_client.core.actions._objects import Action -from adcm_aio_client.core.errors import InvalidFilterError, NotFoundError +from adcm_aio_client.core.errors import InvalidFilterError, NotFoundError, WaitTimeoutError from adcm_aio_client.core.filters import ( ALL_OPERATIONS, COMMON_OPERATIONS, @@ -532,7 +532,7 @@ async def wait( if timeout: message = f"{message} in {timeout} seconds with {poll_interval} second interval" - raise TimeoutError(message) + raise WaitTimeoutError(message) async def terminate(self: Self) -> None: await self._requester.post(*self.get_own_path(), "terminate", data={}) diff --git a/adcm_aio_client/core/requesters.py b/adcm_aio_client/core/requesters.py index 1004774..ddb75cb 100644 --- a/adcm_aio_client/core/requesters.py +++ b/adcm_aio_client/core/requesters.py @@ -21,20 +21,20 @@ import httpx from adcm_aio_client.core.errors import ( + AuthenticationError, BadRequestError, ConflictError, - ForbiddenError, LoginError, LogoutError, NoCredentialsError, NotFoundError, OperationError, + PermissionDeniedError, ResponseDataConversionError, - ResponseError, RetryRequestError, ServerError, UnauthorizedError, - WrongCredentialsError, + UnknownError, ) from adcm_aio_client.core.types import ( Credentials, @@ -92,7 +92,7 @@ def _get_json_data(self: Self) -> Json: STATUS_ERRORS_MAP = { 400: BadRequestError, 401: UnauthorizedError, - 403: ForbiddenError, + 403: PermissionDeniedError, 404: NotFoundError, 409: ConflictError, 500: ServerError, @@ -104,7 +104,7 @@ def convert_exceptions(func: DoRequestFunc) -> DoRequestFunc: async def wrapper(*arg: Params.args, **kwargs: Params.kwargs) -> httpx.Response: response = await func(*arg, **kwargs) if response.status_code >= 300: - error_cls = STATUS_ERRORS_MAP.get(response.status_code, ResponseError) + error_cls = STATUS_ERRORS_MAP.get(response.status_code, UnknownError) # not safe, because can be not json try: message = response.json() @@ -173,8 +173,8 @@ async def login(self: Self, credentials: Credentials) -> Self: f"Login to ADCM at {self.client.base_url} has failed for " f"user {credentials.username} most likely due to incorrect credentials" ) - raise WrongCredentialsError(message) from e - except ResponseError as e: + raise AuthenticationError(message) from e + except UnknownError as e: message = f"Login to ADCM at {self.client.base_url} has failed for user {credentials.username}: {e}" raise LoginError(message) from e @@ -190,7 +190,7 @@ async def logout(self: Self) -> Self: try: request_coro = self.client.post(url=logout_url, data={}) await self._do_request(request_coro) - except ResponseError as e: + except UnknownError as e: message = f"Logout from ADCM at {self.client.base_url} has failed" raise LogoutError(message) from e diff --git a/tests/integration/test_upgrade.py b/tests/integration/test_upgrade.py index e991e72..9ac064e 100644 --- a/tests/integration/test_upgrade.py +++ b/tests/integration/test_upgrade.py @@ -12,7 +12,7 @@ ConfigNoParameterError, NoConfigInActionError, NoMappingInActionError, - ResponseError, + UnknownError, ) from adcm_aio_client.core.filters import Filter from adcm_aio_client.core.mapping.refresh import apply_remote_changes @@ -211,7 +211,7 @@ async def _test_upgrade_with_mapping(context: Context) -> None: config["params", ParameterGroup]["pass", Parameter].set("notenough") # quite strange pick of response in here in ADCM, so generalized expected error - with pytest.raises(ResponseError, match=".*config key.*is required"): + with pytest.raises(UnknownError, match=".*config key.*is required"): await upgrade.run() config["string_field", Parameter].set("useless yet required") diff --git a/tests/unit/test_requesters.py b/tests/unit/test_requesters.py index 0fc1d42..b24d474 100644 --- a/tests/unit/test_requesters.py +++ b/tests/unit/test_requesters.py @@ -7,7 +7,7 @@ import pytest import pytest_asyncio -from adcm_aio_client.core.errors import ResponseDataConversionError, ResponseError +from adcm_aio_client.core.errors import ResponseDataConversionError, UnknownError from adcm_aio_client.core.requesters import DefaultRequester, HTTPXRequesterResponse from adcm_aio_client.core.types import RetryPolicy @@ -93,7 +93,7 @@ async def test_raising_client_error_for_status( partial(requester.patch, data={}), requester.delete, ): - with pytest.raises(ResponseError): + with pytest.raises(UnknownError): await method()