Skip to content

Commit

Permalink
fix: add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Saboteur7 committed Nov 15, 2024
1 parent 9421d44 commit cf84e57
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions plugins/linkai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ def set_reply_text(content: str, e_context: EventContext, level: ReplyType = Rep

@staticmethod
def fetch_app_plugin(app_code: str, plugin_name: str) -> bool:
headers = {"Authorization": "Bearer " + conf().get("linkai_api_key")}
# do http request
base_url = conf().get("linkai_api_base", "https://api.link-ai.tech")
params = {"app_code": app_code}
res = requests.get(url=base_url + "/v1/app/info", params=params, headers=headers, timeout=(5, 10))
if res.status_code == 200:
plugins = res.json().get("data").get("plugins")
for plugin in plugins:
if plugin.get("name") and plugin.get("name") == plugin_name:
return True
return False
else:
logger.warning(f"[LinkAI] find app info exception, res={res}")
try:
headers = {"Authorization": "Bearer " + conf().get("linkai_api_key")}
# do http request
base_url = conf().get("linkai_api_base", "https://api.link-ai.tech")
params = {"app_code": app_code}
res = requests.get(url=base_url + "/v1/app/info", params=params, headers=headers, timeout=(5, 10))
if res.status_code == 200:
plugins = res.json().get("data").get("plugins")
for plugin in plugins:
if plugin.get("name") and plugin.get("name") == plugin_name:
return True
return False
else:
logger.warning(f"[LinkAI] find app info exception, res={res}")
return False
except Exception as e:
return False

0 comments on commit cf84e57

Please sign in to comment.