修复泥点不足错误展示

将资产计费余额不足映射为公开错误文案

补充资产计费错误映射单测
This commit is contained in:
2026-06-28 16:55:10 +08:00
parent 567a9110dc
commit 6e470c1e40
@@ -254,17 +254,27 @@ pub(crate) fn map_asset_operation_wallet_error(error: SpacetimeClientError) -> A
error = %message,
"资产操作泥点预扣失败"
);
let status = match &error {
SpacetimeClientError::Procedure(message) if message.contains("泥点余额不足") => {
StatusCode::CONFLICT
}
_ => StatusCode::BAD_GATEWAY,
let is_insufficient_balance = matches!(
&error,
SpacetimeClientError::Procedure(message) if message.contains("泥点余额不足")
);
let status = if is_insufficient_balance {
StatusCode::CONFLICT
} else {
StatusCode::BAD_GATEWAY
};
let public_message = is_insufficient_balance.then(|| message.clone());
AppError::from_status(status).with_details(json!({
let app_error = AppError::from_status(status).with_details(json!({
"provider": "profile-wallet",
"message": message,
}))
}));
if let Some(public_message) = public_message {
app_error.with_message(public_message)
} else {
app_error
}
}
pub(crate) fn should_skip_asset_operation_billing_for_connectivity(
@@ -315,6 +325,24 @@ mod tests {
));
}
#[test]
fn asset_operation_wallet_insufficient_balance_is_public_message() {
let error = map_asset_operation_wallet_error(SpacetimeClientError::Procedure(
"泥点余额不足".to_string(),
));
assert_eq!(error.status_code(), StatusCode::CONFLICT);
assert_eq!(error.code(), "CONFLICT");
assert_eq!(error.message(), "泥点余额不足");
assert_eq!(
error
.details()
.and_then(|details| details.get("message"))
.and_then(serde_json::Value::as_str),
Some("泥点余额不足"),
);
}
#[test]
fn asset_operation_billing_does_not_refund_stale_worker_lease_errors() {
let stale_error = AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({