Skip to content

Commit

Permalink
refine_validate_key_exception (#257)
Browse files Browse the repository at this point in the history
Co-authored-by: Yao Chi <[email protected]>
  • Loading branch information
iYingg and doombeaker authored Dec 12, 2024
1 parent 5978b09 commit 9cb83a3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/bizyair/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 9cb83a3

Please sign in to comment.