diff --git a/openedx/core/djangoapps/user_api/views.py b/openedx/core/djangoapps/user_api/views.py index 5ed7f19b72..a2410df245 100644 --- a/openedx/core/djangoapps/user_api/views.py +++ b/openedx/core/djangoapps/user_api/views.py @@ -25,7 +25,7 @@ from openedx.core.lib.api.authentication import SessionAuthenticationAllowInacti from openedx.core.lib.api.permissions import ApiKeyHeaderPermission from student.cookies import set_logged_in_cookies from student.forms import get_registration_extension_form -from student.views import create_account_with_params +from student.views import create_account_with_params, AccountValidationError from util.json_request import JsonResponse from .accounts import ( @@ -364,6 +364,9 @@ class RegistrationView(APIView): try: user = create_account_with_params(request, data) + except AccountValidationError as err: + errors = { err.field: [{"user_message": err.message}] } + return JsonResponse(errors, status=409) except ValidationError as err: # Should only get non-field errors from this function assert NON_FIELD_ERRORS not in err.message_dict