fix(登录): 登录优化
This commit is contained in:
@@ -38,11 +38,15 @@ def CustomExceptionHandler(ex, context):
|
|||||||
# 调用默认的异常处理函数
|
# 调用默认的异常处理函数
|
||||||
response = exception_handler(ex, context)
|
response = exception_handler(ex, context)
|
||||||
if isinstance(ex, AuthenticationFailed):
|
if isinstance(ex, AuthenticationFailed):
|
||||||
|
# 如果是身份验证错误
|
||||||
|
if response and response.data.get('detail') == "Given token not valid for any token type":
|
||||||
code = 401
|
code = 401
|
||||||
code_type = response.data.get('detail').code
|
msg = ex.detail
|
||||||
if code_type == 'no_active_account':
|
elif response and response.data.get('detail') == "Token is blacklisted":
|
||||||
code=400
|
# token在黑名单
|
||||||
return ErrorResponse(status=HTTP_401_UNAUTHORIZED)
|
return ErrorResponse(status=HTTP_401_UNAUTHORIZED)
|
||||||
|
else:
|
||||||
|
code = 401
|
||||||
msg = ex.detail
|
msg = ex.detail
|
||||||
elif isinstance(ex,Http404):
|
elif isinstance(ex,Http404):
|
||||||
code = 400
|
code = 400
|
||||||
|
|||||||
Reference in New Issue
Block a user