diff --git a/src/api/tests/test_available.py b/src/api/tests/test_available.py index a80290985..dc0f5ee54 100644 --- a/src/api/tests/test_available.py +++ b/src/api/tests/test_available.py @@ -101,15 +101,17 @@ class AvailableViewTest(MockEppLib): self.assertTrue(json.loads(response.content)["available"]) def test_error_handling(self): - """Calling with bad strings raises an error.""" + """Calling with bad strings returns error (error verifying) or unavailable (invalid domain).""" bad_string = "blah!;" request = self.factory.get(API_BASE_PATH + bad_string) request.user = self.user response = available(request, domain=bad_string) self.assertFalse(json.loads(response.content)["available"]) - # domain set to raise error returns false for availability - error_domain_available = available(request, "errordomain.gov") - self.assertRaises(json.loads(error_domain_available.content)["available"]) + # domain set to raise error returns false for availability and error message + error_domain_response = available(request, domain="errordomain.gov") + self.assertFalse(json.loads(error_domain_response.content)["available"]) + self.assertIn("Error finding domain availability", + json.loads(error_domain_response.content)["message"]) class AvailableAPITest(MockEppLib): diff --git a/src/api/views.py b/src/api/views.py index 56a2b786a..d01acaa3f 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -30,8 +30,8 @@ DOMAIN_API_MESSAGES = { ), "invalid": "Enter a domain using only letters, numbers, or hyphens (though we don't recommend using hyphens).", "success": "That domain is available!", - "error": "Error finding domain availability. Please wait a few minutes and try again. If you continue \ - to receive this error after a few tries, contact help@get.gov", + "error": "Error finding domain availability. Please wait a few minutes and try again.\ + If you continue to receive this error after a few tries, contact help@get.gov", } @@ -74,7 +74,7 @@ def check_domain_available(domain): # domain search string doesn't end with .gov, add it on here return Domain.available(domain + ".gov") except Exception as err: - return err + raise err @require_http_methods(["GET"])