diff --git a/src/epplibwrapper/errors.py b/src/epplibwrapper/errors.py index 02b6e5c36..234bed611 100644 --- a/src/epplibwrapper/errors.py +++ b/src/epplibwrapper/errors.py @@ -1,4 +1,4 @@ -from enum import IntEnum +from enum import IntEnum, Enum class ErrorCode(IntEnum): @@ -52,6 +52,10 @@ class ErrorCode(IntEnum): SESSION_LIMIT_EXCEEDED_SERVER_CLOSING_CONNECTION = 2502 +class RegistryErrorMessage(Enum): + REGISTRAR_NOT_LOGGED_IN = "Registrar is not logged in." + + class RegistryError(Exception): """ Overview of registry response codes from RFC 5730. See RFC 5730 for full text. @@ -72,7 +76,11 @@ class RegistryError(Exception): def should_retry(self): # COMMAND_USE_ERROR is returning with message, Registrar is not logged in, # which can be recovered from with a retry - return self.code == ErrorCode.COMMAND_FAILED or self.code == ErrorCode.COMMAND_USE_ERROR + return self.code == ErrorCode.COMMAND_FAILED or ( + self.code == ErrorCode.COMMAND_USE_ERROR + and self.response + and getattr(self.response, "msg", None) == RegistryErrorMessage.REGISTRAR_NOT_LOGGED_IN.value + ) def is_transport_error(self): return self.code == ErrorCode.TRANSPORT_ERROR diff --git a/src/epplibwrapper/tests/test_client.py b/src/epplibwrapper/tests/test_client.py index d47dbdfae..868d3d6f1 100644 --- a/src/epplibwrapper/tests/test_client.py +++ b/src/epplibwrapper/tests/test_client.py @@ -280,7 +280,7 @@ class TestClient(TestCase): mock_close = MagicMock() # create success and failure result messages send_command_success_result = self.fake_result(1000, "Command completed successfully") - send_command_failure_result = self.fake_result(2002, "Registrar is not logging in.") + send_command_failure_result = self.fake_result(2002, "Registrar is not logged in.") # side_effect for send call, initial send(login) succeeds during initialization, next send(command) # fails, subsequent sends (logout, login, command) all succeed send_call_count = 0 @@ -312,7 +312,7 @@ class TestClient(TestCase): self.assertEquals(mock_send.call_count, 5) # Assertion proper logging; note that the mock_logger.info.assert_called_once_with( - "InfoDomainCommand failed and will be retried Error: Registrar is not logging in.| cltrid is cl_tr_id svtrid is sv_tr_id" + "InfoDomainCommand failed and will be retried Error: Registrar is not logged in.| cltrid is cl_tr_id svtrid is sv_tr_id" ) @less_console_noise_decorator