fix(后台接口): 会员升级与档位目录的业务拒绝改为 400
- runtime_profile.rs:新增 is_runtime_profile_membership_domain_error,会员升级报价(非会员 / 重复购买 / 月年互换 / 档位下架 / 非法报价入参)与会员档位目录校验失败统一映射为 400,基础设施错误仍保持 502 Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -1484,14 +1484,14 @@ pub async fn get_profile_play_stats(
|
||||
}
|
||||
|
||||
fn map_runtime_profile_client_error(error: SpacetimeClientError) -> AppError {
|
||||
let is_redeem_code_domain_error = matches!(
|
||||
let is_domain_error = matches!(
|
||||
&error,
|
||||
SpacetimeClientError::Procedure(message)
|
||||
if is_runtime_profile_redeem_code_domain_error(message)
|
||||
if is_runtime_profile_domain_error(message)
|
||||
);
|
||||
let (status, provider) = match &error {
|
||||
SpacetimeClientError::Runtime(_) => (StatusCode::BAD_REQUEST, "runtime-profile"),
|
||||
SpacetimeClientError::Procedure(_) if is_redeem_code_domain_error => {
|
||||
SpacetimeClientError::Procedure(_) if is_domain_error => {
|
||||
(StatusCode::BAD_REQUEST, "runtime-profile")
|
||||
}
|
||||
_ => (StatusCode::BAD_GATEWAY, "spacetimedb"),
|
||||
@@ -1501,12 +1501,29 @@ fn map_runtime_profile_client_error(error: SpacetimeClientError) -> AppError {
|
||||
"provider": provider,
|
||||
"message": error.to_string(),
|
||||
}));
|
||||
if is_redeem_code_domain_error {
|
||||
if is_domain_error {
|
||||
return app_error.with_message(error.to_string());
|
||||
}
|
||||
app_error
|
||||
}
|
||||
|
||||
/// 模块侧的可读业务拒绝以 400 返回,基础设施错误保持 502。
|
||||
fn is_runtime_profile_domain_error(message: &str) -> bool {
|
||||
is_runtime_profile_redeem_code_domain_error(message)
|
||||
|| is_runtime_profile_membership_domain_error(message)
|
||||
}
|
||||
|
||||
fn is_runtime_profile_membership_domain_error(message: &str) -> bool {
|
||||
message.starts_with("会员升级被拒绝: ")
|
||||
|| message.starts_with("会员档位")
|
||||
|| matches!(
|
||||
message,
|
||||
"当前不是会员,请直接选择套餐购买"
|
||||
| "当前套餐已生效,无需重复购买"
|
||||
| "当前会员有效期内不支持月付 / 年付转换,到期后可重新选择"
|
||||
)
|
||||
}
|
||||
|
||||
fn is_runtime_profile_redeem_code_domain_error(message: &str) -> bool {
|
||||
matches!(
|
||||
message,
|
||||
|
||||
Reference in New Issue
Block a user