diff --git a/apps/common/drf/exc_handlers.py b/apps/common/drf/exc_handlers.py index f0a016cf4..ae0688145 100644 --- a/apps/common/drf/exc_handlers.py +++ b/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) diff --git a/apps/perms/utils/asset/user_permission.py b/apps/perms/utils/asset/user_permission.py index 246601e2e..8ca7789f1 100644 --- a/apps/perms/utils/asset/user_permission.py +++ b/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' + )