错误处理 Catch属性 定义捕获策略,处理重试后仍失败的错误,跳转至指定状态。 字段 类型 是否必选 描述 示例值 onErrors []string 是 可匹配的错误类型列表,见常见错误类型。 cf.InvalideArgument http.404 transition Transition 否 参考流程定义介绍中Transition字段说明 说明: 若针对同一错误类型定义多条捕获规则,系统优先应用匹配到的第一条规则。 常见错误类型 以下列出常见错误类型,其他集成服务的错误请参考对应文档。 错误类型 描述 http.{ErrorCode} HTTP请求返回非200的状态码,如: http.404:请求的资源未找到。 http.401:未授权,需验证身份。 http.500:服务器内部错误,建议重试。 cf.{ErrorCode} 函数调用错误码,如cf.404、cf.500。 cf.InvalideArgument 函数调用参数错误。 cf.ParseError 函数调用成功但结果解析失败。 cf.Unknown 函数调用成功但执行出错,未被捕获的错误。 ctapi.{ErrorCode} 普通集成请求错误码,如ctapi.404、ctapi.500。 cloudflow.InvalideArgument 云工作流执行参数错误。 cloudflow.Unkown 云工作流执行未被捕获的错误。 使用示例 示例1:错误重试 若“FetchMyIp”节点产生http.404或http.401错误,系统按定义的重试策略尝试恢复,失败后跳转至Final节点。 plaintext specVersion: '0.8' version: '1.0' name: test start: Pass states: name: Pass type: Operation actions: functionRef: type: Noop transition: nextState: FetchMyIp name: FetchMyIp type: Operation actions: functionRef: type: Http arguments: url: headers: UserAgent: "apifox" retryRef: name: 404RetryPolicy onErrors: http.404 intervalSeconds: 1 maxIntervalSeconds: 5 maxAttempts: 5 backoffRate: 2 name: 401RetryPolicy onErrors: http.401 intervalSeconds: 1 maxIntervalSeconds: 5 maxAttempts: 3 backoffRate: 1 transition: nextState: Final name: Final type: Operation actions: functionRef: type: Noop end: true 说明: http.404:最多尝试5次,初始间隔1秒,倍率2.0,间隔为[1, 2, 4, 5, 5]秒(受maxIntervalSeconds限制)。 http.401:最多尝试3次,间隔固定1秒,倍率1.0。