fix: saasStore require() bug + health check pool formula + DEV error details
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

- saasStore.ts: replace require('./chat/conversationStore') with await import()
  to fix ReferenceError in Vite ESM environment (P1)
- main.rs: fix health check pool usage formula from max_connections - num_idle
  to pool.size() - num_idle, preventing false "degraded" status (P1)
- error.rs: show detailed error messages in ZCLAW_SAAS_DEV=true mode
- Update bug tracker with BUG-003 through BUG-007
This commit is contained in:
iven
2026-04-09 22:23:05 +08:00
parent bd6cf8e05f
commit bf728c34f3
4 changed files with 46 additions and 6 deletions

View File

@@ -127,11 +127,15 @@ impl IntoResponse for SaasError {
fn into_response(self) -> Response {
let status = self.status_code();
let (error_code, message) = match &self {
// 500 错误不泄露内部细节给客户端
// 500 错误不泄露内部细节给客户端 (开发模式除外)
Self::Database(_) | Self::Internal(_) | Self::Io(_)
| Self::Jwt(_) | Self::Config(_) => {
tracing::error!("内部错误 [{}]: {}", self.error_code(), self);
(self.error_code().to_string(), "服务内部错误".to_string())
if std::env::var("ZCLAW_SAAS_DEV").as_deref() == Ok("true") {
(self.error_code().to_string(), format!("[DEV] {}", self))
} else {
(self.error_code().to_string(), "服务内部错误".to_string())
}
}
_ => (self.error_code().to_string(), self.to_string()),
};

View File

@@ -160,8 +160,9 @@ async fn main() -> anyhow::Result<()> {
interval.tick().await;
let pool = &metrics_db;
let total = pool.options().get_max_connections() as usize;
let size = pool.size() as usize;
let idle = pool.num_idle() as usize;
let used = total.saturating_sub(idle);
let used = size.saturating_sub(idle);
let usage_pct = if total > 0 { used * 100 / total } else { 0 };
tracing::info!(
"[PoolMetrics] total={} idle={} used={} usage_pct={}%",
@@ -248,9 +249,10 @@ async fn health_handler(
let pool = &state.db;
let total = pool.options().get_max_connections() as usize;
if total > 0 {
let size = pool.size() as usize;
let idle = pool.num_idle() as usize;
let used = total - idle;
let ratio = used * 100 / total;
let used = size.saturating_sub(idle);
let ratio = if size > 0 { used * 100 / total } else { 0 };
if ratio >= 80 {
return (
axum::http::StatusCode::SERVICE_UNAVAILABLE,