From 95f29a584e31ede60a051256b8cd4fa3d1a0907c Mon Sep 17 00:00:00 2001 From: jiangweidong <1053570670@qq.com> Date: Tue, 23 Apr 2024 12:27:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E8=BF=87=E6=9C=9F500=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/mfa.py | 5 ++++- apps/templates/_mfa_login_field.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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); }); };