diff --git a/pretor/core/database/postgres.py b/pretor/core/database/postgres.py index 6887a63..5806810 100644 --- a/pretor/core/database/postgres.py +++ b/pretor/core/database/postgres.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/core/global_state_machine/global_state_machine.py b/pretor/core/global_state_machine/global_state_machine.py index 1dc94cc..a6f2d49 100644 --- a/pretor/core/global_state_machine/global_state_machine.py +++ b/pretor/core/global_state_machine/global_state_machine.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/core/individual/consciousness_node/consciousness_node.py b/pretor/core/individual/consciousness_node/consciousness_node.py index d3616d1..be0de50 100644 --- a/pretor/core/individual/consciousness_node/consciousness_node.py +++ b/pretor/core/individual/consciousness_node/consciousness_node.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/core/individual/control_node/control_node.py b/pretor/core/individual/control_node/control_node.py index ae8f7ab..d598fb8 100644 --- a/pretor/core/individual/control_node/control_node.py +++ b/pretor/core/individual/control_node/control_node.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/core/individual/supervisory_node/supervisory_node.py b/pretor/core/individual/supervisory_node/supervisory_node.py index 9b60042..784a831 100644 --- a/pretor/core/individual/supervisory_node/supervisory_node.py +++ b/pretor/core/individual/supervisory_node/supervisory_node.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/core/workflow/workflow_runner.py b/pretor/core/workflow/workflow_runner.py index 94edeed..77451f2 100644 --- a/pretor/core/workflow/workflow_runner.py +++ b/pretor/core/workflow/workflow_runner.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pretor/utils/check_user/role_check.py b/pretor/utils/check_user/role_check.py index 0d0986c..a589a62 100644 --- a/pretor/utils/check_user/role_check.py +++ b/pretor/utils/check_user/role_check.py @@ -18,9 +18,24 @@ from pretor.core.database.table.user import UserAuthority from pretor.utils.ray_hook import ray_actor_hook async def get_authority(user_id: str) -> UserAuthority: + from pretor.utils.error import UserNotExistError postgres_database = ray_actor_hook("postgres_database").postgres_database - user_authority = await postgres_database.get_user_authority.remote( user_id=user_id) - return user_authority + try: + user_authority = await postgres_database.get_user_authority.remote(user_id=user_id) + return user_authority + except UserNotExistError: + raise HTTPException( + status_code=401, + detail="用户不存在或已被删除,请重新登录" + ) + except Exception as e: + # Check if it's a RayTaskError wrapping UserNotExistError + if "UserNotExistError" in str(e): + raise HTTPException( + status_code=401, + detail="用户不存在或已被删除,请重新登录" + ) + raise class RoleChecker: def __init__(self, **kwargs): diff --git a/pretor/utils/retry.py b/pretor/utils/retry.py index dcb6052..38f8278 100644 --- a/pretor/utils/retry.py +++ b/pretor/utils/retry.py @@ -11,7 +11,7 @@ def retry_on_retryable_error(max_retries=3, base_delay=1): for attempt in range(max_retries): try: return await func(*args, **kwargs) - except RetryableError as e: + except RetryableError: if attempt == max_retries - 1: raise await asyncio.sleep(base_delay * (2 ** attempt)) @@ -23,7 +23,7 @@ def retry_on_retryable_error(max_retries=3, base_delay=1): for attempt in range(max_retries): try: return func(*args, **kwargs) - except RetryableError as e: + except RetryableError: if attempt == max_retries - 1: raise time.sleep(base_delay * (2 ** attempt)) diff --git a/pretor/worker_individual/worker_cluster.py b/pretor/worker_individual/worker_cluster.py index 602afad..e0e2013 100644 --- a/pretor/worker_individual/worker_cluster.py +++ b/pretor/worker_individual/worker_cluster.py @@ -1,4 +1,3 @@ -from pretor.utils.error import RetryableError # Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License");