Improve error checking in listing users

This commit is contained in:
Sarina
2024-07-23 17:40:00 +03:30
parent f2c9cbf516
commit 69a205a487
2 changed files with 6 additions and 2 deletions

View File

@ -41,7 +41,7 @@ def run_cmd(command: list[str]):
Runs a command and returns the output.
Could raise subprocess.CalledProcessError
'''
if DEBUG and Command.GET_USER.value not in command:
if DEBUG and Command.GET_USER.value not in command and Command.LIST_USERS.value not in command:
print(' '.join(command))
result = subprocess.check_output(command, shell=False)
if DEBUG:

View File

@ -143,7 +143,11 @@ hysteria2_get_user_handler() {
}
hysteria2_list_users_handler() {
users_json=$(python3 $CLI_PATH list-users)
users_json=$(python3 $CLI_PATH list-users 2>/dev/null)
if [ $? -ne 0 ] || [ -z "$users_json" ]; then
echo -e "\033[0;31mError:\033[0m Failed to list users."
return 1
fi
users_array=($(echo "$users_json" | jq -r '.[] | .username'))
if [[ ${#users_array[@]} -eq 0 ]]; then