diff --git a/courseware/api.py b/courseware/api.py index e0d1c6426..9f223f425 100644 --- a/courseware/api.py +++ b/courseware/api.py @@ -14,6 +14,7 @@ from edx_api.client import EdxApi from oauth2_provider.models import AccessToken, Application from oauthlib.common import generate_token +from requests.exceptions import ConnectionError as RequestConnectionError from requests.exceptions import HTTPError from rest_framework import status @@ -848,6 +849,9 @@ def validate_name_with_edx(name): response = edx_client.user_validation.validate_user_registration_info( registration_information={"name": name}, ) + except RequestConnectionError: + # Silently fail if connection cannot be established with the open edx instance. + return "" except Exception as exc: raise EdxApiRegistrationValidationException(name, exc.response) from exc else: diff --git a/courseware/exceptions.py b/courseware/exceptions.py index 79507f17d..795e45afe 100644 --- a/courseware/exceptions.py +++ b/courseware/exceptions.py @@ -78,7 +78,10 @@ def __init__(self, name, error_response, msg=None): """ self.name = name self.response = error_response + error_summary = ( + get_error_response_summary(self.response) if self.response else "" + ) if msg is None: # Set some default useful error message - msg = f"EdX API error validating registration name {self.name}.\n{get_error_response_summary(self.response)}" + msg = f"EdX API error validating registration name {self.name}.\n{error_summary}" super().__init__(msg)