mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-31 15:06:32 +02:00
consolidation of nameserver view error messages
This commit is contained in:
parent
293eb40cff
commit
2bf7847654
3 changed files with 19 additions and 9 deletions
|
@ -75,7 +75,7 @@ class DomainNameserverForm(forms.Form):
|
|||
ip_list = [ip.strip() for ip in ip.split(",")]
|
||||
if not server and len(ip_list) > 0:
|
||||
# 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
|
||||
|
||||
|
@ -88,9 +88,15 @@ class DomainNameserverForm(forms.Form):
|
|||
Domain.checkHostIPCombo(domain, server, ip_list)
|
||||
except NameserverError as e:
|
||||
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:
|
||||
self.add_error('ip', "Subdomains require an IP address")
|
||||
self.add_error(
|
||||
'ip',
|
||||
NameserverError(code=nsErrorCodes.MISSING_IP)
|
||||
)
|
||||
else:
|
||||
self.add_error('ip', str(e))
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class NameserverErrorCodes(IntEnum):
|
|||
INVALID_IP = 3
|
||||
TOO_MANY_HOSTS = 4
|
||||
UNABLE_TO_UPDATE_DOMAIN = 5
|
||||
MISSING_HOST = 6
|
||||
|
||||
|
||||
class NameserverError(Exception):
|
||||
|
@ -45,10 +46,10 @@ class NameserverError(Exception):
|
|||
"""
|
||||
|
||||
_error_mapping = {
|
||||
NameserverErrorCodes.MISSING_IP: "Nameserver {} needs to have an "
|
||||
"IP address because it is a subdomain",
|
||||
NameserverErrorCodes.GLUE_RECORD_NOT_ALLOWED: "Nameserver {} cannot be linked "
|
||||
"because it is not a subdomain",
|
||||
NameserverErrorCodes.MISSING_IP: "Subdomains require an IP address",
|
||||
NameserverErrorCodes.GLUE_RECORD_NOT_ALLOWED: (
|
||||
"Name server address does not match domain name"
|
||||
),
|
||||
NameserverErrorCodes.INVALID_IP: "Nameserver {} has an invalid IP address: {}",
|
||||
NameserverErrorCodes.TOO_MANY_HOSTS: (
|
||||
"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."
|
||||
"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):
|
||||
|
|
|
@ -318,10 +318,10 @@ class DomainNameserversView(DomainFormBaseView, BaseFormSet):
|
|||
# TODO: merge 1103 and use literals
|
||||
except RegistryError as Err:
|
||||
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}")
|
||||
else:
|
||||
messages.error(self.request, 'GENERIC_ERROR')
|
||||
messages.error(self.request, GENERIC_ERROR)
|
||||
logger.error(f"Registry error: {Err}")
|
||||
else:
|
||||
messages.success(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue