mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 19:48:36 +02:00
Update domain_helper.py
This commit is contained in:
parent
89431b111d
commit
a7fa332d36
1 changed files with 8 additions and 19 deletions
|
@ -37,18 +37,6 @@ class DomainHelper:
|
||||||
if not isinstance(domain, str):
|
if not isinstance(domain, str):
|
||||||
raise errors.InvalidDomainError("Domain name must be a string")
|
raise errors.InvalidDomainError("Domain name must be a string")
|
||||||
|
|
||||||
domain = DomainHelper._parse_domain_string(domain, blank_ok)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if not check_domain_available(domain):
|
|
||||||
raise errors.DomainUnavailableError()
|
|
||||||
except RegistryError as err:
|
|
||||||
raise errors.RegistrySystemError() from err
|
|
||||||
return domain
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parse_domain_string(domain: str, blank_ok) -> str:
|
|
||||||
"""Parses '.gov' out of the domain_name string, and does some validation on it"""
|
|
||||||
domain = domain.lower().strip()
|
domain = domain.lower().strip()
|
||||||
|
|
||||||
if domain == "" and not blank_ok:
|
if domain == "" and not blank_ok:
|
||||||
|
@ -63,6 +51,13 @@ class DomainHelper:
|
||||||
if not DomainHelper.string_could_be_domain(domain + ".gov"):
|
if not DomainHelper.string_could_be_domain(domain + ".gov"):
|
||||||
raise errors.InvalidDomainError()
|
raise errors.InvalidDomainError()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not check_domain_available(domain):
|
||||||
|
raise errors.DomainUnavailableError()
|
||||||
|
except RegistryError as err:
|
||||||
|
raise errors.RegistrySystemError() from err
|
||||||
|
return domain
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_handle_errors(cls, domain: str, error_return_type: str, display_success: bool = False):
|
def validate_and_handle_errors(cls, domain: str, error_return_type: str, display_success: bool = False):
|
||||||
"""Runs validate() and catches possible exceptions."""
|
"""Runs validate() and catches possible exceptions."""
|
||||||
|
@ -88,10 +83,6 @@ class DomainHelper:
|
||||||
return DomainHelper._return_form_error_or_json_response(
|
return DomainHelper._return_form_error_or_json_response(
|
||||||
error_return_type, code="invalid"
|
error_return_type, code="invalid"
|
||||||
)
|
)
|
||||||
except Exception:
|
|
||||||
return DomainHelper._return_form_error_or_json_response(
|
|
||||||
error_return_type, code="error"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
if display_success:
|
if display_success:
|
||||||
return DomainHelper._return_form_error_or_json_response(
|
return DomainHelper._return_form_error_or_json_response(
|
||||||
|
@ -102,11 +93,9 @@ class DomainHelper:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _return_form_error_or_json_response(return_type, code, available=False):
|
def _return_form_error_or_json_response(return_type, code, available=False):
|
||||||
print(f"What is the code? {code}")
|
|
||||||
if return_type == "JSON_RESPONSE":
|
if return_type == "JSON_RESPONSE":
|
||||||
print("in the return context")
|
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{"available": available, "code": code, "message": DOMAIN_API_MESSAGES[code]}
|
{"available": available, "code": code, "message": DOMAIN_API_MESSAGES[code]}
|
||||||
)
|
)
|
||||||
|
|
||||||
if return_type == "FORM_VALIDATION_ERROR":
|
if return_type == "FORM_VALIDATION_ERROR":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue