From 9cb83a35671556c30896ccb476336d97a0d55fc1 Mon Sep 17 00:00:00 2001 From: Zjtt <117345396+iYingg@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:25:58 +0800 Subject: [PATCH] refine_validate_key_exception (#257) Co-authored-by: Yao Chi --- src/bizyair/common/client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bizyair/common/client.py b/src/bizyair/common/client.py index a990fb6a..ee78fbb2 100644 --- a/src/bizyair/common/client.py +++ b/src/bizyair/common/client.py @@ -49,7 +49,6 @@ def validate_api_key(api_key: str = None) -> bool: api_key_state.current_api_key = api_key url = f"{BIZYAIR_SERVER_ADDRESS}/user/info" headers = {"accept": "application/json", "authorization": f"Bearer {api_key}"} - try: response_data = send_request( method="GET", url=url, headers=headers, callback=None @@ -59,9 +58,15 @@ def validate_api_key(api_key: str = None) -> bool: print(f"\033[91mAPI key validation failed. API Key: {api_key}\033[0m") else: api_key_state.is_valid = True + except ConnectionError as ce: + api_key_state.is_valid = False + print(f"\033[91mConnection error: {ce}\033[0m") + except PermissionError as pe: + api_key_state.is_valid = False + print(f"\033[91mError validating API key: {api_key}, error: {pe}\033[0m") except Exception as e: api_key_state.is_valid = False - print(f"\033[91mError validating API key: {api_key}, error: {e}\033[0m") + print(f"\033[91mOther error: {e}\033[0m") return api_key_state.is_valid