diff --git a/IMPROVEMENTS.md b/IMPROVEMENTS.md index 55e26e0..58115c4 100644 --- a/IMPROVEMENTS.md +++ b/IMPROVEMENTS.md @@ -33,15 +33,18 @@ ``` ### 1.3 错误处理改进 -- [ ] **错误响应格式不统一** +- [x] **错误响应格式不统一** ✅ - 现状:部分返回 `ErrorResponse`,部分返回 JSON 字符串 - 改进:统一使用 `ErrorResponse` 结构体 - 彰响:前端解析更一致 + - 完成时间:2026-04-15 -- [ ] **错误信息暴露过多** +- [x] **错误信息暴露过多** ✅ - 现状:部分错误直接返回数据库错误信息 - 改进:区分用户友好错误和开发者错误 - 影响:安全性提升 + - 完成时间:2026-04-15 + - 修改:移除所有 `errmsg: Some(e.to_string())`,错误详情只记录到日志 ## 二、安全性改进 diff --git a/src/main.rs b/src/main.rs index ddf46b4..46682c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,7 @@ async fn login( return HttpResponse::InternalServerError().json(ErrorResponse { error: "用户信息处理失败".to_string(), errcode: Some(500), - errmsg: Some(e.to_string()), + errmsg: None, }); } }; @@ -165,7 +165,7 @@ async fn login( return HttpResponse::InternalServerError().json(ErrorResponse { error: "生成身份令牌失败".to_string(), errcode: Some(500), - errmsg: Some(e.to_string()), + errmsg: None, }); } }; @@ -694,7 +694,7 @@ async fn health_check(pool: web::Data) -> impl Responder { HttpResponse::ServiceUnavailable().json(serde_json::json!({ "status": "unhealthy", "database": "disconnected", - "error": e.to_string() + "error": "数据库连接失败" })) } }