Browse Source

fix(perms): 重建授权树冲突时,响应里加 code

pull/4928/head
xinwen 4 years ago committed by Jiangjie.Bai
parent
commit
231332585d
  1. 6
      apps/common/drf/exc_handlers.py
  2. 5
      apps/perms/utils/asset/user_permission.py

6
apps/common/drf/exc_handlers.py

@ -39,10 +39,10 @@ def common_exception_handler(exc, context):
if getattr(exc, 'wait', None):
headers['Retry-After'] = '%d' % exc.wait
if isinstance(exc.detail, (list, dict)):
data = exc.detail
if isinstance(exc.detail, str) and isinstance(exc.get_codes(), str):
data = {'detail': exc.detail, 'code': exc.get_codes()}
else:
data = {'detail': exc.detail}
data = exc.detail
set_rollback()
return Response(data, status=exc.status_code, headers=headers)

5
apps/perms/utils/asset/user_permission.py

@ -507,4 +507,7 @@ def rebuild_user_tree_if_need(request, user):
rebuild_user_mapping_nodes_with_lock(user)
except lock.SomeoneIsDoingThis:
# 您的数据正在初始化,请稍等
raise lock.SomeoneIsDoingThis(detail=_('Please wait while your data is being initialized'))
raise lock.SomeoneIsDoingThis(
detail=_('Please wait while your data is being initialized'),
code='rebuild_tree_conflict'
)

Loading…
Cancel
Save