Skip to content

Commit

Permalink
fix: silently fail name validation on connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Aug 21, 2024
1 parent 1ceb478 commit 61b7b02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions courseware/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion courseware/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 61b7b02

Please sign in to comment.