File tree Expand file tree Collapse file tree
astrbot/core/agent/runners/dify Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -235,6 +235,15 @@ async def _execute_dify_request(self):
235235 ):
236236 logger .debug (f"dify workflow resp chunk: { chunk } " )
237237 match chunk ["event" ]:
238+ case "error" :
239+ logger .error (
240+ f"Dify workflow error (status: { chunk .get ('status' )} , "
241+ f"code: { chunk .get ('code' )} ): "
242+ f"{ chunk .get ('message' ) or 'No error details provided.' } "
243+ )
244+ raise Exception (
245+ "Dify workflow execution failed. Please contact the administrator."
246+ )
238247 case "workflow_started" :
239248 logger .info (
240249 f"Dify 工作流(ID: { chunk ['workflow_run_id' ]} )开始运行。"
@@ -258,18 +267,27 @@ async def _execute_dify_request(self):
258267 f"Dify 工作流(ID: { chunk ['workflow_run_id' ]} )运行结束"
259268 )
260269 logger .debug (f"Dify 工作流结果:{ chunk } " )
261- if chunk ["data" ]["error" ]:
270+ status = chunk ["data" ].get ("status" )
271+ if chunk ["data" ].get ("error" ) or status not in (
272+ "succeeded" ,
273+ "partial-succeeded" ,
274+ ):
262275 logger .error (
263- f"Dify 工作流出现错误:{ chunk ['data' ]['error' ]} "
276+ f"Dify workflow failed (status: { status } ): "
277+ f"{ chunk ['data' ].get ('error' ) or 'No error details provided.' } "
264278 )
265279 raise Exception (
266- f "Dify 工作流出现错误: { chunk [ 'data' ][ 'error' ] } "
280+ "Dify workflow execution failed. Please contact the administrator. "
267281 )
268282 if self .workflow_output_key not in chunk ["data" ]["outputs" ]:
269283 raise Exception (
270284 f"Dify 工作流的输出不包含指定的键名:{ self .workflow_output_key } "
271285 )
272286 result = chunk
287+ if not result :
288+ raise Exception (
289+ "Dify workflow stream ended without a successful workflow_finished event."
290+ )
273291 case _:
274292 raise Exception (f"未知的 Dify API 类型:{ self .api_type } " )
275293
You can’t perform that action at this time.
0 commit comments