mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 09:07:02 +02:00
more consolidation of error messages and their text
This commit is contained in:
parent
d532449b3d
commit
182d1a61c0
5 changed files with 101 additions and 21 deletions
|
@ -45,7 +45,7 @@ except NameError:
|
|||
# Attn: these imports should NOT be at the top of the file
|
||||
try:
|
||||
from .client import CLIENT, commands
|
||||
from .errors import RegistryError, ErrorCode, CANNOT_CONTACT_REGISTRY, GENERIC_ERROR
|
||||
from .errors import RegistryError, ErrorCode
|
||||
from epplib.models import common, info
|
||||
from epplib.responses import extensions
|
||||
from epplib import responses
|
||||
|
@ -61,6 +61,4 @@ __all__ = [
|
|||
"info",
|
||||
"ErrorCode",
|
||||
"RegistryError",
|
||||
"CANNOT_CONTACT_REGISTRY",
|
||||
"GENERIC_ERROR",
|
||||
]
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
from enum import IntEnum
|
||||
|
||||
CANNOT_CONTACT_REGISTRY = "Update failed. Cannot contact the registry."
|
||||
GENERIC_ERROR = "Value entered was wrong."
|
||||
|
||||
|
||||
class ErrorCode(IntEnum):
|
||||
"""
|
||||
|
|
|
@ -75,10 +75,21 @@ class DomainNameserverForm(forms.Form):
|
|||
if e.code == nsErrorCodes.GLUE_RECORD_NOT_ALLOWED:
|
||||
self.add_error(
|
||||
"server",
|
||||
NameserverError(code=nsErrorCodes.GLUE_RECORD_NOT_ALLOWED),
|
||||
NameserverError(
|
||||
code=nsErrorCodes.GLUE_RECORD_NOT_ALLOWED,
|
||||
nameserver=domain,
|
||||
ip=ip_list
|
||||
),
|
||||
)
|
||||
elif e.code == nsErrorCodes.MISSING_IP:
|
||||
self.add_error("ip", NameserverError(code=nsErrorCodes.MISSING_IP))
|
||||
self.add_error(
|
||||
"ip",
|
||||
NameserverError(
|
||||
code=nsErrorCodes.MISSING_IP,
|
||||
nameserver=domain,
|
||||
ip=ip_list,
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.add_error("ip", str(e))
|
||||
|
||||
|
|
|
@ -20,6 +20,41 @@ class ActionNotAllowed(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class GenericErrorCodes(IntEnum):
|
||||
"""Used across the registrar for
|
||||
error mapping.
|
||||
Overview of generic error codes:
|
||||
- 1 GENERIC_ERROR a generic value error
|
||||
- 2 CANNOT_CONTACT_REGISTRY a connection error w registry
|
||||
"""
|
||||
|
||||
GENERIC_ERROR = 1
|
||||
CANNOT_CONTACT_REGISTRY = 2
|
||||
|
||||
|
||||
class GenericError(Exception):
|
||||
"""
|
||||
GenericError class used to raise exceptions across
|
||||
the registrar
|
||||
"""
|
||||
|
||||
_error_mapping = {
|
||||
GenericErrorCodes.CANNOT_CONTACT_REGISTRY: "Update failed. Cannot contact the registry.",
|
||||
GenericErrorCodes.GENERIC_ERROR: (
|
||||
"Value entered was wrong."
|
||||
),
|
||||
}
|
||||
|
||||
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 NameserverErrorCodes(IntEnum):
|
||||
"""Used in the NameserverError class for
|
||||
error mapping.
|
||||
|
@ -29,6 +64,8 @@ class NameserverErrorCodes(IntEnum):
|
|||
value but is not a subdomain
|
||||
- 3 INVALID_IP invalid ip address format or invalid version
|
||||
- 4 TOO_MANY_HOSTS more than the max allowed host values
|
||||
- 5 UNABLE_TO_UPDATE_DOMAIN unable to update the domain
|
||||
- 6 MISSING_HOST host is missing for a nameserver
|
||||
"""
|
||||
|
||||
MISSING_IP = 1
|
||||
|
|
|
@ -24,7 +24,12 @@ from registrar.models import (
|
|||
UserDomainRole,
|
||||
)
|
||||
from registrar.models.public_contact import PublicContact
|
||||
from registrar.utility.errors import NameserverError
|
||||
from registrar.utility.errors import (
|
||||
GenericError,
|
||||
GenericErrorCodes,
|
||||
NameserverError,
|
||||
NameserverErrorCodes as nsErrorCodes,
|
||||
)
|
||||
from registrar.models.utility.contact_error import ContactError
|
||||
|
||||
from ..forms import (
|
||||
|
@ -44,8 +49,6 @@ from epplibwrapper import (
|
|||
common,
|
||||
extensions,
|
||||
RegistryError,
|
||||
CANNOT_CONTACT_REGISTRY,
|
||||
GENERIC_ERROR,
|
||||
)
|
||||
|
||||
from ..utility.email import send_templated_email, EmailSendingError
|
||||
|
@ -311,18 +314,32 @@ class DomainNameserversView(DomainFormBaseView):
|
|||
try:
|
||||
self.object.nameservers = nameservers
|
||||
except NameserverError as Err:
|
||||
# TODO: move into literal
|
||||
messages.error(self.request, "Whoops, Nameservers Error")
|
||||
# messages.error(self.request, GENERIC_ERROR)
|
||||
# NamserverErrors *should* be caught in form; if reached here,
|
||||
# there was an uncaught error in submission (through EPP)
|
||||
messages.error(
|
||||
self.request,
|
||||
NameserverError(
|
||||
code=nsErrorCodes.UNABLE_TO_UPDATE_DOMAIN
|
||||
)
|
||||
)
|
||||
logger.error(f"Nameservers error: {Err}")
|
||||
# TODO: registry is not throwing an error when no connection
|
||||
# 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,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.CANNOT_CONTACT_REGISTRY
|
||||
)
|
||||
)
|
||||
logger.error(f"Registry connection error: {Err}")
|
||||
else:
|
||||
messages.error(self.request, GENERIC_ERROR)
|
||||
messages.error(
|
||||
self.request,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.GENERIC_ERROR
|
||||
)
|
||||
)
|
||||
logger.error(f"Registry error: {Err}")
|
||||
else:
|
||||
messages.success(
|
||||
|
@ -688,7 +705,12 @@ class DomainSecurityEmailView(DomainFormBaseView):
|
|||
# If no default is created for security_contact,
|
||||
# then we cannot connect to the registry.
|
||||
if contact is None:
|
||||
messages.error(self.request, CANNOT_CONTACT_REGISTRY)
|
||||
messages.error(
|
||||
self.request,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.CANNOT_CONTACT_REGISTRY
|
||||
)
|
||||
)
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
contact.email = new_email
|
||||
|
@ -697,13 +719,28 @@ class DomainSecurityEmailView(DomainFormBaseView):
|
|||
contact.save()
|
||||
except RegistryError as Err:
|
||||
if Err.is_connection_error():
|
||||
messages.error(self.request, CANNOT_CONTACT_REGISTRY)
|
||||
messages.error(
|
||||
self.request,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.CANNOT_CONTACT_REGISTRY
|
||||
)
|
||||
)
|
||||
logger.error(f"Registry connection error: {Err}")
|
||||
else:
|
||||
messages.error(self.request, GENERIC_ERROR)
|
||||
messages.error(
|
||||
self.request,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.GENERIC_ERROR
|
||||
)
|
||||
)
|
||||
logger.error(f"Registry error: {Err}")
|
||||
except ContactError as Err:
|
||||
messages.error(self.request, GENERIC_ERROR)
|
||||
messages.error(
|
||||
self.request,
|
||||
GenericError(
|
||||
code=GenericErrorCodes.GENERIC_ERROR
|
||||
)
|
||||
)
|
||||
logger.error(f"Generic registry error: {Err}")
|
||||
else:
|
||||
messages.success(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue