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.
This commit is contained in:
committed by
Po Tsui
parent
ead5e9f919
commit
6e617fe2a6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user