1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use std::{borrow::Cow, fmt::Debug}; /// 场景错误统一接口:需实现 [`Debug`] 与错误分类 [`ScenarioError::kind`]。 /// /// 新增 [`ScenarioError::is_timeout`] 用于区分“软失败”:请求超时被视为 /// 被测系统过载信号,不计入 `failures`,而是单列为 `timeouts` 并触发退避。 pub trait ScenarioError: Debug { fn kind(&self) -> Cow<'static, str>; /// 是否属于超时类软失败(默认否)。 /// 为 `true` 时:不计入失败,计入超时统计;runner 在下一轮前退避等待。 fn is_timeout(&self) -> bool { false } /// 错误携带的 HTTP 状态码(默认无)。 /// /// 框架不解析错误文本,只按该钩子聚合 4xx/5xx 计数 /// (见 [`crate::recorder::Recorder::status_counts`])。 /// 非 HTTP 错误保持默认 `None`。 fn status_code(&self) -> Option<u16> { None } }