Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

Commit 6ef5f6d

Browse files
committed
fix(api): align user data with response model in user detail endpoint
1 parent 842b78c commit 6ef5f6d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • core/scripts/webpanel/routers/api/v1

core/scripts/webpanel/routers/api/v1/user.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,18 @@ async def get_user_api(username: str):
126126
HTTPException: if the user is not found, or if an error occurs.
127127
"""
128128
try:
129-
if res := cli_api.get_user(username):
130-
return res
131-
raise HTTPException(status_code=404, detail=f'User {username} not found.')
129+
user_data = cli_api.get_user(username)
130+
if not user_data:
131+
raise HTTPException(status_code=404, detail=f'User {username} not found.')
132+
133+
if '_id' in user_data:
134+
user_data['username'] = user_data.pop('_id')
135+
136+
return user_data
137+
except json.JSONDecodeError as e:
138+
raise HTTPException(status_code=500, detail=f"Failed to parse user data from CLI: {e}")
132139
except Exception as e:
133-
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
140+
raise HTTPException(status_code=500, detail=f'An unexpected error occurred: {str(e)}')
134141

135142

136143
@router.patch('/{username}', response_model=DetailResponse)

0 commit comments

Comments
 (0)