3D 查价错误并入统一的定价错误枚举

- EditorGenerationPricingError 新增 Model3d 变体并实现 From<Model3dPricingError>
- model3d_price 改为返回 EditorGenerationPricingError,内层文案直通保持响应不变
- 提交路由对 3D 定价错误与定价快照错误分别映射,未配置用例改断言 Model3d(NotConfigured)
This commit is contained in:
2026-09-22 16:11:17 +08:00
parent 9800477c7c
commit c8b4160fcd
2 changed files with 27 additions and 3 deletions
@@ -93,21 +93,33 @@ pub(crate) enum EditorGenerationPricingError {
Io(io::Error),
Json(serde_json::Error),
Invalid(String),
/// 3D 定价查询失败:结构化保留「未配置 / 缺底价 / 缺加价项」三种语义。
Model3d(Model3dPricingError),
#[cfg_attr(test, allow(dead_code))]
Persistence(String),
LockPoisoned,
}
impl From<Model3dPricingError> for EditorGenerationPricingError {
fn from(error: Model3dPricingError) -> Self {
Self::Model3d(error)
}
}
impl EditorGenerationPricingConfig {
/// Tripo 3D 提交查价:缺段或缺键都直接报错,不回退默认值。
///
/// 错误与同文件其它查询统一成 [`EditorGenerationPricingError`]3D 结构化原因收在
/// [`EditorGenerationPricingError::Model3d`] 里,调用方不必再处理第二套错误枚举。
pub(crate) fn model3d_price(
&self,
query: &Model3dPricingQuery,
) -> Result<u32, Model3dPricingError> {
) -> Result<u32, EditorGenerationPricingError> {
self.model3d
.as_ref()
.ok_or(Model3dPricingError::NotConfigured)?
.price(query)
.map_err(Into::into)
}
/// 后台 payload 的「可省略」语义:`model3d` 缺席或为 null 表示沿用当前 3D 段。
@@ -657,6 +669,8 @@ impl fmt::Display for EditorGenerationPricingError {
Self::Invalid(message) => write!(f, "模型定价配置不合法:{message}"),
Self::Persistence(message) => write!(f, "模型定价配置入库失败:{message}"),
Self::LockPoisoned => write!(f, "模型定价配置锁已损坏"),
// 直接透传内层文案,保持接口响应里的 message 与改造前一致。
Self::Model3d(error) => write!(f, "{error}"),
}
}
}
@@ -760,7 +774,13 @@ mod tests {
),
))
.expect_err("未配置 3D 定价时应拒绝查价");
assert_eq!(error, Model3dPricingError::NotConfigured);
assert!(
matches!(
error,
EditorGenerationPricingError::Model3d(Model3dPricingError::NotConfigured)
),
"3D 段缺失应以 NotConfigured 收口,实际 {error:?}"
);
}
/// 受控默认配置里的 3D 泥点价必须严格等于 `ceil(0.8 × Tripo 官方 credit)`
@@ -146,9 +146,13 @@ async fn resolve_price_mud_points(
.map_err(|error| error.into_response_with_context(Some(request_context)))?;
match pricing.model3d_price(query) {
Ok(price_mud_points) => Ok(u64::from(price_mud_points)),
Err(error) => {
// 查价失败只有 3D 定价这一种原因;其它变体理论上不会出现,真出现时按服务端问题上报。
Err(crate::editor_generation_config::EditorGenerationPricingError::Model3d(error)) => {
Err(map_pricing_error(error).into_response_with_context(Some(request_context)))
}
Err(error) => {
Err(map_pricing_store_error(error).into_response_with_context(Some(request_context)))
}
}
}