Skip to content

Commit c61fb86

Browse files
authored
Merge pull request #535 from Lingghh/dev/login_api_opti
🎨完善登录接口异常处理和错误提示
2 parents eb15b27 + b0e750e commit c61fb86

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

server/projects/login/login/apis/v3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"""
99
login - v3 apis
1010
"""
11-
import logging
1211
# 原生
12+
import logging
1313
import os
1414

1515
# 第三方
@@ -218,7 +218,7 @@ def post(self, request, *args, **kwargs):
218218
raise NotAuthenticated("账号或密码不正确")
219219
except Exception as e:
220220
logger.exception("OAInfo登录失败: %s" % e)
221-
raise ParseError("登录失败,请稍后再试")
221+
raise ParseError("登录失败,账户或密码错误或账户未注册")
222222
return Response(params)
223223

224224

server/projects/login/login/lib/rendererresponse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
class CustomRenderer(JSONRenderer):
1717
# 重构render方法
1818
def render(self, data, accepted_media_type=None, renderer_context=None):
19-
2019
status_code = renderer_context["response"].status_code
2120
code = 0
2221
if renderer_context:
2322
msg = ""
2423
status = status_code
2524
if data:
2625
if isinstance(data, dict):
27-
msg = data.pop("msg", "success")
26+
msg = data.pop("msg", None)
27+
detail = data.pop("detail", None)
28+
msg = msg or detail or "success"
2829
status = data.pop("status", status_code)
2930
code = 0
3031
elif isinstance(data, list):

server/projects/login/login/middleware/loginmiddleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def handle_auth_authorization(self, request):
5151
auth_type = settings.OAUTH_JWT['AUTH_HEADER_TYPES'][0]
5252
pub_key = settings.OAUTH_JWT['VERIFYING_KEY']
5353
life_time = settings.OAUTH_JWT['ACCESS_TOKEN_LIFETIME']
54-
5554
now_time = datetime.now()
55+
5656
if auth_type in authorization:
5757
access_token = authorization.replace('%s ' % auth_type, '')
5858
decoded_jwt = jwt.decode(access_token, pub_key, algorithm='RS256')
@@ -75,7 +75,8 @@ def handle_auth_authorization(self, request):
7575
else:
7676
request.oauth = None
7777
else:
78+
logger.warning("[auth_type: %s] auth type not in authorization" % auth_type)
7879
request.oauth = None
7980
except Exception as e:
8081
logger.exception(e)
81-
raise e
82+
return Response({"exception_message": "鉴权失败", "status": -1})

0 commit comments

Comments
 (0)