datawhalechina/hello-agents · warning · HTTPException
用户不存在
Error message
用户不存在
What it means
HTTPException 404 '用户不存在' at api/routes/users.py:60 raised when db_manager.get_user returns falsy for the given user_id in GET /users/{user_id}. The user row simply does not exist (never created, deleted, or wrong id format).
Source
Thrown at Co-creation-projects/Apricity-InnocoreAI/api/routes/users.py:60
return UserResponse(
id=user["id"],
email=user["email"],
profile=user["profile"],
created_at=user["created_at"].isoformat() if user["created_at"] else ""
)
except Exception as e:
logger.error(f"创建用户失败: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
@router.get("/{user_id}", response_model=UserResponse)
async def get_user(user_id: str):
"""获取用户信息"""
try:
user = await db_manager.get_user(user_id)
if not user:
raise HTTPException(status_code=404, detail="用户不存在")
return UserResponse(
id=user["id"],
email=user["email"],
profile=user["profile"],
created_at=user["created_at"].isoformat() if user["created_at"] else ""
)
except HTTPException:
raise
except Exception as e:
logger.error(f"获取用户信息失败: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
@router.put("/{user_id}", response_model=Dict[str, Any])
async def update_user(user_id: str, request: UserUpdateRequest):
"""更新用户信息"""
try:View on GitHub (pinned to 606a07d341)
Solutions
- Verify the id by listing users or checking the creation response that returned it.
- Confirm you're pointed at the right database/environment.
- Trim/validate the id client-side before the call.
- If the user should exist, check the DB directly for the row and any deletion logic in db_manager.
Example fix
// before
const user = await api.get(`/users/${userId}`);
// after
if (!userId || userId === 'undefined') throw new Error('missing userId');
const user = await api.get(`/users/${encodeURIComponent(userId.trim())}`); Defensive patterns
Strategy: validation
Validate before calling
assert user_id and user_id not in ('undefined','null','None')
resp = await client.get(f"/users/{user_id}")
if resp.status_code == 404: handle_missing_user() Type guard
def is plausible_user_id(uid: str) -> bool:
return isinstance(uid, str) and len(uid.strip()) > 0 and uid not in {"undefined", "null"} Try / catch
try:
user = await client.get(f"/users/{user_id}").json()
except NotFoundError:
user = None # first-run / deleted user; create if needed Prevention
- Derive user ids from a live session, not localStorage
- Validate ids client-side before requests
- Handle 404 as a state, not an error
When it happens
Trigger: GET /users/{user_id} with an id not present in the database; user deleted; id copied with whitespace/case differences if the DB collation is case-sensitive.
Common situations: Client stores a stale user id after DB reset; frontend passes undefined producing 'None'/'undefined' string ids; environment mismatch (querying dev DB for a prod-created user).
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/57db8a60bbd4a4a8.
Report an issue: GitHub.