mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
Merge pull request #3141 from xinnan-tech/add-correct-word
fix修复 asyncio.gather 吞掉业务异常的问题
This commit is contained in:
@@ -2,7 +2,14 @@ import os
|
||||
import asyncio
|
||||
import yaml
|
||||
from collections.abc import Mapping
|
||||
from config.manage_api_client import init_service, get_server_config, get_agent_models, get_correct_words
|
||||
from config.manage_api_client import (
|
||||
init_service,
|
||||
get_server_config,
|
||||
get_agent_models,
|
||||
get_correct_words,
|
||||
DeviceNotFoundException,
|
||||
DeviceBindException,
|
||||
)
|
||||
|
||||
|
||||
def get_project_dir():
|
||||
@@ -91,10 +98,18 @@ async def get_private_config_from_api(config, device_id, client_id):
|
||||
results = await asyncio.gather(
|
||||
get_agent_models(device_id, client_id, config["selected_module"]),
|
||||
get_correct_words(device_id),
|
||||
return_exceptions=True
|
||||
return_exceptions=True,
|
||||
)
|
||||
private_config = results[0] if not isinstance(results[0], Exception) else {}
|
||||
agent_result = results[0]
|
||||
correct_words = results[1] if not isinstance(results[1], Exception) else None
|
||||
|
||||
# 抛出业务异常
|
||||
if isinstance(agent_result, DeviceNotFoundException):
|
||||
raise agent_result
|
||||
if isinstance(agent_result, DeviceBindException):
|
||||
raise agent_result
|
||||
|
||||
private_config = agent_result if not isinstance(agent_result, Exception) else {}
|
||||
if correct_words:
|
||||
private_config["correct_words"] = correct_words
|
||||
return private_config
|
||||
|
||||
Reference in New Issue
Block a user