- 入门指南
- 面向 Administrator
- RPA 工作流项目
- 应用程序项目
- 智能体流程
- Maestro 案例
- Maestro Orchestrate 中的流画布
- Agents (智能体)
- Functions
- Solutions (解决方案)
- API 工作流
- 测试
Try Catch 异常处理
将“Try Catch 异常处理”活动添加到 Studio Web 中的 API 工作流中,以便使用回退操作处理由 API 故障、无效数据或意外错误导致的异常。
“Try Catch异常处理”活动在工作流中提供结构化异常处理。使用它来定义 API 故障、数据无效或意外错误的回退操作。
使用“Try Catch 异常处理”活动
要将“Try Catch 异常处理”活动添加到工作流中,请执行以下操作:
-
在 API 工作流设计器画布上,选择加号 (+) 图标。系统将显示“添加活动”菜单。
-
选择“更多…” ,然后选择“Try Catch 异常处理”。
-
在“属性”面板中,为错误命名。
-
Optionally, configure retries for the Try block:
- Retry—Turn on to automatically retry the Try block when it fails. Off by default.
- Max retries—The maximum number of retry attempts.
- Initial delay—The delay before the first retry attempt.
- Backoff—The strategy used to increase the delay between subsequent retry attempts.
The Preview of retry schedule panel shows the computed delay for each retry attempt based on these settings.
-
前往“尝试”块添加活动。这是为错误而监控的活动。
-
在Catch块中定义错误处理逻辑。如果Try块中的任何步骤失败,则执行将转换到Catch流程。
-
调试工作流以执行活动并生成输出字段以供以后使用。
When retries are enabled, each retry attempt appears as a separate entry in the run output, so you can review the result of every attempt.
访问错误详情
当Try块中发生错误时, “Try-Catch 异常处理”活动会公开结构化的错误详细信息。要访问错误详细信息,请使用$context.outputs.Try_Catch_X.error或$error 。
错误对象保持一致的结构,如下所示:
"Try_Catch_1": {
"error": {
"type": "<runtime error source>",
"title": "<summary error message>",
"status": <response status code>,
"detail": "<detailed error message",
"data": {},
}
}
"Try_Catch_1": {
"error": {
"type": "<runtime error source>",
"title": "<summary error message>",
"status": <response status code>,
"detail": "<detailed error message",
"data": {},
}
}
错误详细信息包括:
- 类型— 指示错误的 Runtime 来源。
- title — 提供简明的错误摘要。
- “状态” — HTTP 状态代码(如果适用)。
- detail — 提供错误的详细说明。
- data — 包括有关失败任务的其他元数据。此字段可能并不总是处于填充状态。
您可以引用这些属性来构建结构化错误响应或触发警示。