diff --git a/apps/authentication/api/mfa.py b/apps/authentication/api/mfa.py index ed88b116e..703ddccbd 100644 --- a/apps/authentication/api/mfa.py +++ b/apps/authentication/api/mfa.py @@ -50,7 +50,10 @@ class MFASendCodeApi(AuthMixin, CreateAPIView): mfa_type = serializer.validated_data['type'] if not username: - user = self.get_user_from_session() + try: + user = self.get_user_from_session() + except errors.SessionEmptyError as e: + raise ValidationError({'error': e}) else: user = self.get_user_from_db(username) diff --git a/apps/templates/_mfa_login_field.html b/apps/templates/_mfa_login_field.html index ec2477d1f..463e5732e 100644 --- a/apps/templates/_mfa_login_field.html +++ b/apps/templates/_mfa_login_field.html @@ -120,7 +120,7 @@ function onError (responseText, responseJson, status) { setTimeout(function () { - toastr.error(responseJson.detail); + toastr.error(responseJson.detail || responseJson.error); }); };