Commit 6e617fe2 by Nishant Karandikar Committed by Po Tsui

Catch exception with duplicate username/email

Previously, there was no catch for the AccountValidationError
exception raised by the account creation function. If, for some
reason, the user made it past the first check for a duplicate
username/email, then the exception was raised, uncaught, and
crashed the server.
parent ead5e9f9
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment