Commit bff03e4d by baiquan

refactor(service): 优化关闭浏览器逻辑

- 将关闭浏览器的逻辑包裹在 try-except块中,提高异常处理的健壮性
parent 4a8724ee
...@@ -99,16 +99,16 @@ async def closeBrowser(browser_id): ...@@ -99,16 +99,16 @@ async def closeBrowser(browser_id):
data = { data = {
'containerCode': browser_id, 'containerCode': browser_id,
} }
browser_status = await checkBrowserStatus(browser_id) try:
browser_status_data = browser_status.get('data', {}) browser_status = await checkBrowserStatus(browser_id)
if browser_status_data: browser_status_data = browser_status.get('data', {})
containers = browser_status_data.get('containers', {}) if browser_status_data:
if containers: containers = browser_status_data.get('containers', {})
try: if containers:
if (containers[0]['status'] == 1 or containers[0]['status'] == 0) and containers[0]['containerCode'] == browser_id: if (containers[0]['status'] == 1 or containers[0]['status'] == 0) and containers[0]['containerCode'] == browser_id:
return await sendRequest("POST", url=url, json_data=data) return await sendRequest("POST", url=url, json_data=data)
except Exception as e: except Exception as e:
logger.error(f"关闭浏览器异常-->{e}") logger.error(f"关闭浏览器异常-->{e}")
async def checkBrowserStatus(browser_id: str = ""): async def checkBrowserStatus(browser_id: str = ""):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment