mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-22 12:29:25 +02:00
error handling for generic error messages in nameserver, dsdata and security email forms
This commit is contained in:
parent
778fbdb737
commit
624871de2d
2 changed files with 75 additions and 4 deletions
|
@ -69,6 +69,7 @@ class NameserverErrorCodes(IntEnum):
|
||||||
- 5 UNABLE_TO_UPDATE_DOMAIN unable to update the domain
|
- 5 UNABLE_TO_UPDATE_DOMAIN unable to update the domain
|
||||||
- 6 MISSING_HOST host is missing for a nameserver
|
- 6 MISSING_HOST host is missing for a nameserver
|
||||||
- 7 INVALID_HOST host is invalid for a nameserver
|
- 7 INVALID_HOST host is invalid for a nameserver
|
||||||
|
- 8 BAD_DATA bad data input for nameserver
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MISSING_IP = 1
|
MISSING_IP = 1
|
||||||
|
@ -78,6 +79,7 @@ class NameserverErrorCodes(IntEnum):
|
||||||
UNABLE_TO_UPDATE_DOMAIN = 5
|
UNABLE_TO_UPDATE_DOMAIN = 5
|
||||||
MISSING_HOST = 6
|
MISSING_HOST = 6
|
||||||
INVALID_HOST = 7
|
INVALID_HOST = 7
|
||||||
|
BAD_DATA = 8
|
||||||
|
|
||||||
|
|
||||||
class NameserverError(Exception):
|
class NameserverError(Exception):
|
||||||
|
@ -96,6 +98,9 @@ class NameserverError(Exception):
|
||||||
),
|
),
|
||||||
NameserverErrorCodes.MISSING_HOST: ("Name server must be provided to enter IP address."),
|
NameserverErrorCodes.MISSING_HOST: ("Name server must be provided to enter IP address."),
|
||||||
NameserverErrorCodes.INVALID_HOST: ("Enter a name server in the required format, like ns1.example.com"),
|
NameserverErrorCodes.INVALID_HOST: ("Enter a name server in the required format, like ns1.example.com"),
|
||||||
|
NameserverErrorCodes.BAD_DATA: (
|
||||||
|
"There’s something wrong with the name server information you provided. If you need help email us at help@get.gov."
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs):
|
def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs):
|
||||||
|
@ -112,3 +117,65 @@ class NameserverError(Exception):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.message}"
|
return f"{self.message}"
|
||||||
|
|
||||||
|
|
||||||
|
class DsDataErrorCodes(IntEnum):
|
||||||
|
"""Used in the DsDataError class for
|
||||||
|
error mapping.
|
||||||
|
Overview of ds data error codes:
|
||||||
|
- 1 BAD_DATA bad data input in ds data
|
||||||
|
"""
|
||||||
|
|
||||||
|
BAD_DATA = 1
|
||||||
|
|
||||||
|
|
||||||
|
class DsDataError(Exception):
|
||||||
|
"""
|
||||||
|
DsDataError class used to raise exceptions on
|
||||||
|
the ds data getter
|
||||||
|
"""
|
||||||
|
|
||||||
|
_error_mapping = {
|
||||||
|
DsDataErrorCodes.BAD_DATA: (
|
||||||
|
"There’s something wrong with the DS data you provided. If you need help email us at help@get.gov."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, code=None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.code = code
|
||||||
|
if self.code in self._error_mapping:
|
||||||
|
self.message = self._error_mapping.get(self.code)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.message}"
|
||||||
|
|
||||||
|
|
||||||
|
class SecurityEmailErrorCodes(IntEnum):
|
||||||
|
"""Used in the SecurityEmailError class for
|
||||||
|
error mapping.
|
||||||
|
Overview of security email error codes:
|
||||||
|
- 1 BAD_DATA bad data input in security email
|
||||||
|
"""
|
||||||
|
|
||||||
|
BAD_DATA = 1
|
||||||
|
|
||||||
|
|
||||||
|
class SecurityEmailError(Exception):
|
||||||
|
"""
|
||||||
|
SecurityEmailError class used to raise exceptions on
|
||||||
|
the security email form
|
||||||
|
"""
|
||||||
|
|
||||||
|
_error_mapping = {
|
||||||
|
SecurityEmailErrorCodes.BAD_DATA: ("Enter an email address in the required format, like name@example.com.")
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, code=None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.code = code
|
||||||
|
if self.code in self._error_mapping:
|
||||||
|
self.message = self._error_mapping.get(self.code)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.message}"
|
||||||
|
|
|
@ -28,6 +28,10 @@ from registrar.utility.errors import (
|
||||||
GenericErrorCodes,
|
GenericErrorCodes,
|
||||||
NameserverError,
|
NameserverError,
|
||||||
NameserverErrorCodes as nsErrorCodes,
|
NameserverErrorCodes as nsErrorCodes,
|
||||||
|
DsDataError,
|
||||||
|
DsDataErrorCodes,
|
||||||
|
SecurityEmailError,
|
||||||
|
SecurityEmailErrorCodes,
|
||||||
)
|
)
|
||||||
from registrar.models.utility.contact_error import ContactError
|
from registrar.models.utility.contact_error import ContactError
|
||||||
|
|
||||||
|
@ -315,7 +319,7 @@ class DomainNameserversView(DomainFormBaseView):
|
||||||
)
|
)
|
||||||
logger.error(f"Registry connection error: {Err}")
|
logger.error(f"Registry connection error: {Err}")
|
||||||
else:
|
else:
|
||||||
messages.error(self.request, GenericError(code=GenericErrorCodes.GENERIC_ERROR))
|
messages.error(self.request, NameserverError(code=nsErrorCodes.BAD_DATA))
|
||||||
logger.error(f"Registry error: {Err}")
|
logger.error(f"Registry error: {Err}")
|
||||||
else:
|
else:
|
||||||
messages.success(
|
messages.success(
|
||||||
|
@ -491,7 +495,7 @@ class DomainDsDataView(DomainFormBaseView):
|
||||||
)
|
)
|
||||||
logger.error(f"Registry connection error: {err}")
|
logger.error(f"Registry connection error: {err}")
|
||||||
else:
|
else:
|
||||||
messages.error(self.request, GenericError(code=GenericErrorCodes.GENERIC_ERROR))
|
messages.error(self.request, DsDataError(code=DsDataErrorCodes.BAD_DATA))
|
||||||
logger.error(f"Registry error: {err}")
|
logger.error(f"Registry error: {err}")
|
||||||
return self.form_invalid(formset)
|
return self.form_invalid(formset)
|
||||||
else:
|
else:
|
||||||
|
@ -581,10 +585,10 @@ class DomainSecurityEmailView(DomainFormBaseView):
|
||||||
)
|
)
|
||||||
logger.error(f"Registry connection error: {Err}")
|
logger.error(f"Registry connection error: {Err}")
|
||||||
else:
|
else:
|
||||||
messages.error(self.request, GenericError(code=GenericErrorCodes.GENERIC_ERROR))
|
messages.error(self.request, SecurityEmailError(code=SecurityEmailErrorCodes.BAD_DATA))
|
||||||
logger.error(f"Registry error: {Err}")
|
logger.error(f"Registry error: {Err}")
|
||||||
except ContactError as Err:
|
except ContactError as Err:
|
||||||
messages.error(self.request, GenericError(code=GenericErrorCodes.GENERIC_ERROR))
|
messages.error(self.request, SecurityEmailError(code=SecurityEmailErrorCodes.BAD_DATA))
|
||||||
logger.error(f"Generic registry error: {Err}")
|
logger.error(f"Generic registry error: {Err}")
|
||||||
else:
|
else:
|
||||||
messages.success(self.request, "The security email for this domain has been updated.")
|
messages.success(self.request, "The security email for this domain has been updated.")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue