mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-21 20:09:23 +02:00
moved nameserver error to utility
This commit is contained in:
parent
851c58953b
commit
01ad6b5523
5 changed files with 56 additions and 54 deletions
|
@ -15,7 +15,7 @@ from epplibwrapper import (
|
|||
RegistryError,
|
||||
ErrorCode,
|
||||
)
|
||||
from registrar.models.utility.nameserver_error import (
|
||||
from registrar.utility.errors import (
|
||||
NameserverError,
|
||||
NameserverErrorCodes as nsErrorCodes,
|
||||
)
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
from enum import IntEnum
|
||||
|
||||
|
||||
class NameserverErrorCodes(IntEnum):
|
||||
"""Used in the NameserverError class for
|
||||
error mapping.
|
||||
Overview of nameserver error codes:
|
||||
- 1 MISSING_IP ip address is missing for a nameserver
|
||||
- 2 GLUE_RECORD_NOT_ALLOWED a host has a nameserver
|
||||
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
|
||||
"""
|
||||
|
||||
MISSING_IP = 1
|
||||
GLUE_RECORD_NOT_ALLOWED = 2
|
||||
INVALID_IP = 3
|
||||
TOO_MANY_HOSTS = 4
|
||||
|
||||
|
||||
class NameserverError(Exception):
|
||||
"""
|
||||
NameserverError class used to raise exceptions on
|
||||
the nameserver getter
|
||||
"""
|
||||
|
||||
_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.INVALID_IP: "Nameserver {} has an invalid IP address: {}",
|
||||
NameserverErrorCodes.TOO_MANY_HOSTS: (
|
||||
"Too many hosts provided, you may not have more than " "13 nameservers."
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.code = code
|
||||
if self.code in self._error_mapping:
|
||||
self.message = self._error_mapping.get(self.code)
|
||||
if nameserver is not None and ip is not None:
|
||||
self.message = self.message.format(str(nameserver), str(ip))
|
||||
elif nameserver is not None:
|
||||
self.message = self.message.format(str(nameserver))
|
||||
elif ip is not None:
|
||||
self.message = self.message.format(str(ip))
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.message}"
|
|
@ -16,7 +16,7 @@ from registrar.models.domain_information import DomainInformation
|
|||
from registrar.models.draft_domain import DraftDomain
|
||||
from registrar.models.public_contact import PublicContact
|
||||
from registrar.models.user import User
|
||||
from registrar.models.utility.nameserver_error import NameserverError
|
||||
from registrar.utility.errors import NameserverError
|
||||
from .common import MockEppLib
|
||||
from django_fsm import TransitionNotAllowed # type: ignore
|
||||
from epplibwrapper import (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from registrar.models.utility.nameserver_error import (
|
||||
from registrar.utility.errors import (
|
||||
NameserverError,
|
||||
NameserverErrorCodes as nsErrorCodes,
|
||||
)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from enum import IntEnum
|
||||
|
||||
|
||||
class BlankValueError(ValueError):
|
||||
pass
|
||||
|
||||
|
@ -8,3 +11,53 @@ class ExtraDotsError(ValueError):
|
|||
|
||||
class DomainUnavailableError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class NameserverErrorCodes(IntEnum):
|
||||
"""Used in the NameserverError class for
|
||||
error mapping.
|
||||
Overview of nameserver error codes:
|
||||
- 1 MISSING_IP ip address is missing for a nameserver
|
||||
- 2 GLUE_RECORD_NOT_ALLOWED a host has a nameserver
|
||||
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
|
||||
"""
|
||||
|
||||
MISSING_IP = 1
|
||||
GLUE_RECORD_NOT_ALLOWED = 2
|
||||
INVALID_IP = 3
|
||||
TOO_MANY_HOSTS = 4
|
||||
|
||||
|
||||
class NameserverError(Exception):
|
||||
"""
|
||||
NameserverError class used to raise exceptions on
|
||||
the nameserver getter
|
||||
"""
|
||||
|
||||
_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.INVALID_IP: "Nameserver {} has an invalid IP address: {}",
|
||||
NameserverErrorCodes.TOO_MANY_HOSTS: (
|
||||
"Too many hosts provided, you may not have more than " "13 nameservers."
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, code=None, nameserver=None, ip=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.code = code
|
||||
if self.code in self._error_mapping:
|
||||
self.message = self._error_mapping.get(self.code)
|
||||
if nameserver is not None and ip is not None:
|
||||
self.message = self.message.format(str(nameserver), str(ip))
|
||||
elif nameserver is not None:
|
||||
self.message = self.message.format(str(nameserver))
|
||||
elif ip is not None:
|
||||
self.message = self.message.format(str(ip))
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.message}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue