wip commit

This commit is contained in:
David Kennedy 2023-09-21 12:17:57 -04:00
parent 4db5b94b36
commit 34106286a6
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
4 changed files with 48 additions and 5 deletions

View file

@ -67,6 +67,9 @@ class RegistryError(Exception):
def should_retry(self):
return self.code == ErrorCode.COMMAND_FAILED
def is_session_error(self):
return self.code is not None and (self.code >= 2501 and self.code <= 2502)
def is_server_error(self):
return self.code is not None and (self.code >= 2400 and self.code <= 2500)

View file

@ -311,7 +311,17 @@ class DomainAdmin(ListHeaderAdmin):
obj.place_client_hold()
obj.save()
except Exception as err:
self.message_user(request, err, messages.ERROR)
# if error is an error from the registry, display useful
# and readable error
if err.code:
self.message_user(
request,
"Error placing the hold with the registry: {err}",
messages.ERROR
)
else:
# all other type error messages, display the error
self.message_user(request, err, messages.ERROR)
else:
self.message_user(
request,
@ -328,7 +338,17 @@ class DomainAdmin(ListHeaderAdmin):
obj.revert_client_hold()
obj.save()
except Exception as err:
self.message_user(request, err, messages.ERROR)
# if error is an error from the registry, display useful
# and readable error
if err.code:
self.message_user(
request,
"Error removing the hold in the registry: {err}",
messages.ERROR
)
else:
# all other type error messages, display the error
self.message_user(request, err, messages.ERROR)
else:
self.message_user(
request,

View file

@ -635,13 +635,29 @@ class Domain(TimeStampedModel, DomainHelper):
"""This domain should not be active.
may raises RegistryError, should be caught or handled correctly by caller"""
request = commands.UpdateDomain(name=self.name, add=[self.clientHoldStatus()])
registry.send(request, cleaned=True)
try:
registry.send(request, cleaned=True)
self._invalidate_cache()
except RegistryError as err:
# if registry error occurs, log the error, and raise it as well
logger.error(
f"registry error placing client hold: {err}"
)
raise (err)
def _remove_client_hold(self):
"""This domain is okay to be active.
may raises RegistryError, should be caught or handled correctly by caller"""
request = commands.UpdateDomain(name=self.name, rem=[self.clientHoldStatus()])
registry.send(request, cleaned=True)
try:
registry.send(request, cleaned=True)
self._invalidate_cache()
except RegistryError as err:
# if registry error occurs, log the error, and raise it as well
logger.error(
f"registry error removing client hold: {err}"
)
raise (err)
def _delete_domain(self):
"""This domain should be deleted from the registry

View file

@ -634,7 +634,11 @@ class TestAnalystClientHold(TestCase):
Given the analyst is logged in
And a domain exists in the registry
"""
pass
super().setUp()
self.domain, _ = Domain.objects.get_or_create(name="security.gov")
def tearDown(self):
super().tearDown()
@skip("not implemented yet")
def test_analyst_places_client_hold(self):