- 开始使用
- 构建
- HTTP 请求
- 连接器节点的工作方式
- 创建连接
- 销售和客户关系
- 客户支持和服务台
- 消息传递和会议
- 电子邮件
- 营销
- 社交媒体
- 文件、文档和电子签名
- 项目、协作和代码
- 人员和招聘
- 财务和商业
- AI 模型和智能体
- 语音、视觉和语言
- 数据和位置
- 云、身份和安全性
- 部署并运行
- 示例
- 参考
处理错误
Route failed nodes to an error path, return the error details, retry temporary failures, and end the workflow cleanly on unrecoverable errors.
您构建的内容
A workflow that routes a failing node to a separate path, records the failure with useful context, retries temporary failures where that makes sense, and ends cleanly when the error is unrecoverable. The result is a pattern that fits into any existing workflow.
开始之前
- 至少包含一个可能失败的节点的现有工作流,并具有“错误处理”选项卡,例如“HTTP 请求”或“提取节点”。
使用的节点
步骤
编码智能体设置后,您可以跳过手动步骤。询问:
Add error handling to the HTTP Request node in this Maestro Automate workflow: connect its error path to a Script node that returns the error message, retry temporary failures, and end the run with a Terminate node when the error can't be recovered.
Add error handling to the HTTP Request node in this Maestro Automate workflow: connect its error path to a Script node that returns the error message, retry temporary failures, and end the run with a Terminate node when the error can't be recovered.
然后在画布上打开工作流,根据以下步骤进行检查并进行测试。“设置编码智能体”描述了相关设置。
1. 连接节点的错误句柄
默认情况下,故障节点会停止整个工作流。要改为处理故障:
-
在画布上打开工作流,然后选择可能失败的节点。
-
打开“错误处理”选项卡,然后启用“启用错误处理” 。主输出句柄下方显示“错误”句柄。
-
选择“错误”句柄上的“ +” ,搜索“脚本” ,然后选择它。
这将创建错误路径。当节点发生故障时,系统将遵循此路径运行,而不会停止工作流。没有“错误句柄”的节点不支持错误处理,若节点发生故障,工作流会停止,并显示在“故障”选项卡中。
2. Return the error details
In the Script node on the error path, read the error object at $vars.<node>.error and return the details:
const error = $vars.httpRequest1.error;
return {
message: "Error raised: " + error.message,
code: error.code,
status: error.status
};
const error = $vars.httpRequest1.error;
return {
message: "Error raised: " + error.message,
code: error.code,
status: error.status
};
The Script node's output appears in the execution trace, so the error details are visible when you inspect the run. The error object is only populated on the error path. The Error handling page lists the full set of error fields.
3. 重试暂时性失败(可选)
如果故障可能是暂时的,例如网络中断或速率限制,在放弃之前重试会有所帮助。“HTTP 请求”节点具有内置的重试功能:在其“高级”选项卡上设置“重试计数”可使其在触发错误句柄之前多次重新尝试请求。只有最终失败会路由到错误路径。
仅重试可以多次安全运行的操作。重试带有副作用(例如写入数据或发送消息)的节点会创建重复项。
4. 无法恢复时终止
在错误路径上的“脚本”节点后,添加“终止”节点。要返回故障描述,请在节点上选择“添加输出变量” ,并为其提供一个包含错误的值,例如$vars.httpRequest1.error.message 。
工作流在“终止”节点结束,该运行列在“监控运行”中。
5. 测试和调试
要有意触发错误路径:
- 请暂时将“HTTP 请求”节点中的 URL 设置为无效值(例如
https://this-will-fail.example.com)。 - 在画布底部工具栏中选择“运行调试”(中断),并验证执行追踪记录是否遵循错误路径。
- 还原正确的 URL。
In the trace, select the Script node and check its output for the error message.
结果
The workflow routes failures to the error path, returns the error details, optionally retries temporary failures, and ends cleanly with a descriptive failure status. An invalid URL in the HTTP Request node confirms that the error path works.
扩展此工作流
- 失败时发送警示:在错误路径上的“终止”节点之前,添加 HTTP 请求或连接器节点,以通知Slack频道或创建ServiceNow事件。
- 继续而不是终止:如果步骤不关键,则让错误路径设置回退值并重新加入主路径,而不是终止。
- Apply this pattern widely: the Error handling page describes more patterns, such as returning error details and continuing, fallback values, and escalation.