consolidation of nameserver view error messages

This commit is contained in:
David Kennedy 2023-10-24 08:15:04 -04:00
parent 293eb40cff
commit 2bf7847654
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 19 additions and 9 deletions

View file

@ -75,7 +75,7 @@ class DomainNameserverForm(forms.Form):
ip_list = [ip.strip() for ip in ip.split(",")] ip_list = [ip.strip() for ip in ip.split(",")]
if not server and len(ip_list) > 0: if not server and len(ip_list) > 0:
# If 'server' is empty, disallow 'ip' input # If 'server' is empty, disallow 'ip' input
self.add_error('server', "Name server must be provided to enter IP address.") self.add_error('server', NameserverError(code=nsErrorCodes.MISSING_HOST))
# if there's a nameserver and an ip, validate nameserver/ip combo # if there's a nameserver and an ip, validate nameserver/ip combo
@ -88,9 +88,15 @@ class DomainNameserverForm(forms.Form):
Domain.checkHostIPCombo(domain, server, ip_list) Domain.checkHostIPCombo(domain, server, ip_list)
except NameserverError as e: except NameserverError as e:
if e.code == nsErrorCodes.GLUE_RECORD_NOT_ALLOWED: if e.code == nsErrorCodes.GLUE_RECORD_NOT_ALLOWED:
self.add_error('server', "Name server address does not match domain name") self.add_error(
'server',
NameserverError(code=nsErrorCodes.GLUE_RECORD_NOT_ALLOWED)
)
elif e.code == nsErrorCodes.MISSING_IP: elif e.code == nsErrorCodes.MISSING_IP:
self.add_error('ip', "Subdomains require an IP address") self.add_error(
'ip',
NameserverError(code=nsErrorCodes.MISSING_IP)
)
else: else:
self.add_error('ip', str(e)) self.add_error('ip', str(e))

View file

@ -36,6 +36,7 @@ class NameserverErrorCodes(IntEnum):
INVALID_IP = 3 INVALID_IP = 3
TOO_MANY_HOSTS = 4 TOO_MANY_HOSTS = 4
UNABLE_TO_UPDATE_DOMAIN = 5 UNABLE_TO_UPDATE_DOMAIN = 5
MISSING_HOST = 6
class NameserverError(Exception): class NameserverError(Exception):
@ -45,10 +46,10 @@ class NameserverError(Exception):
""" """
_error_mapping = { _error_mapping = {
NameserverErrorCodes.MISSING_IP: "Nameserver {} needs to have an " NameserverErrorCodes.MISSING_IP: "Subdomains require an IP address",
"IP address because it is a subdomain", NameserverErrorCodes.GLUE_RECORD_NOT_ALLOWED: (
NameserverErrorCodes.GLUE_RECORD_NOT_ALLOWED: "Nameserver {} cannot be linked " "Name server address does not match domain name"
"because it is not a subdomain", ),
NameserverErrorCodes.INVALID_IP: "Nameserver {} has an invalid IP address: {}", NameserverErrorCodes.INVALID_IP: "Nameserver {} has an invalid IP address: {}",
NameserverErrorCodes.TOO_MANY_HOSTS: ( NameserverErrorCodes.TOO_MANY_HOSTS: (
"Too many hosts provided, you may not have more than 13 nameservers." "Too many hosts provided, you may not have more than 13 nameservers."
@ -57,6 +58,9 @@ class NameserverError(Exception):
"Unable to update domain, changes were not applied." "Unable to update domain, changes were not applied."
"Check logs as a Registry Error is the likely cause" "Check logs as a Registry Error is the likely cause"
), ),
NameserverErrorCodes.MISSING_HOST: (
"Name server must be provided to enter IP address."
),
} }
def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs): def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs):

View file

@ -318,10 +318,10 @@ class DomainNameserversView(DomainFormBaseView, BaseFormSet):
# TODO: merge 1103 and use literals # TODO: merge 1103 and use literals
except RegistryError as Err: except RegistryError as Err:
if Err.is_connection_error(): if Err.is_connection_error():
messages.error(self.request, 'CANNOT_CONTACT_REGISTRY') messages.error(self.request, CANNOT_CONTACT_REGISTRY)
logger.error(f"Registry connection error: {Err}") logger.error(f"Registry connection error: {Err}")
else: else:
messages.error(self.request, 'GENERIC_ERROR') messages.error(self.request, GENERIC_ERROR)
logger.error(f"Registry error: {Err}") logger.error(f"Registry error: {Err}")
else: else:
messages.success( messages.success(