Some checks failed
BotServer CI / build (push) Failing after 1m34s
Split 20+ files over 1000 lines into focused subdirectories for better maintainability and code organization. All changes maintain backward compatibility through re-export wrappers. Major splits: - attendance/llm_assist.rs (2074→7 modules) - basic/keywords/face_api.rs → face_api/ (7 modules) - basic/keywords/file_operations.rs → file_ops/ (8 modules) - basic/keywords/hear_talk.rs → hearing/ (6 modules) - channels/wechat.rs → wechat/ (10 modules) - channels/youtube.rs → youtube/ (5 modules) - contacts/mod.rs → contacts_api/ (6 modules) - core/bootstrap/mod.rs → bootstrap/ (5 modules) - core/shared/admin.rs → admin_*.rs (5 modules) - designer/canvas.rs → canvas_api/ (6 modules) - designer/mod.rs → designer_api/ (6 modules) - docs/handlers.rs → handlers_api/ (11 modules) - drive/mod.rs → drive_handlers.rs, drive_types.rs - learn/mod.rs → types.rs - main.rs → main_module/ (7 modules) - meet/webinar.rs → webinar_api/ (8 modules) - paper/mod.rs → (10 modules) - security/auth.rs → auth_api/ (7 modules) - security/passkey.rs → (4 modules) - sources/mod.rs → sources_api/ (5 modules) - tasks/mod.rs → task_api/ (5 modules) Stats: 38,040 deletions, 1,315 additions across 318 files Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
82 lines
1.9 KiB
Rust
82 lines
1.9 KiB
Rust
//! Health check and client error handlers
|
|
|
|
use axum::extract::State;
|
|
use axum::http::StatusCode;
|
|
use axum::Json;
|
|
use std::sync::Arc;
|
|
|
|
use crate::core::shared::state::AppState;
|
|
|
|
pub async fn health_check(State(state): State<Arc<AppState>>) -> (StatusCode, Json<serde_json::Value>) {
|
|
let db_ok = state.conn.get().is_ok();
|
|
|
|
let status = if db_ok { "healthy" } else { "degraded" };
|
|
let code = if db_ok {
|
|
StatusCode::OK
|
|
} else {
|
|
StatusCode::SERVICE_UNAVAILABLE
|
|
};
|
|
|
|
(
|
|
code,
|
|
Json(serde_json::json!({
|
|
"status": status,
|
|
"service": "botserver",
|
|
"version": env!("CARGO_PKG_VERSION"),
|
|
"database": db_ok
|
|
})),
|
|
)
|
|
}
|
|
|
|
pub async fn health_check_simple() -> (StatusCode, Json<serde_json::Value>) {
|
|
(
|
|
StatusCode::OK,
|
|
Json(serde_json::json!({
|
|
"status": "ok",
|
|
"service": "botserver",
|
|
"version": env!("CARGO_PKG_VERSION")
|
|
})),
|
|
)
|
|
}
|
|
|
|
#[derive(serde::Deserialize)]
|
|
pub struct ClientErrorsRequest {
|
|
errors: Vec<ClientErrorData>,
|
|
}
|
|
|
|
#[derive(serde::Deserialize)]
|
|
pub struct ClientErrorData {
|
|
#[serde(default)]
|
|
r#type: String,
|
|
#[serde(default)]
|
|
message: String,
|
|
#[serde(default)]
|
|
stack: Option<String>,
|
|
#[serde(default)]
|
|
url: String,
|
|
#[serde(default)]
|
|
timestamp: String,
|
|
}
|
|
|
|
pub async fn receive_client_errors(
|
|
Json(payload): Json<ClientErrorsRequest>,
|
|
) -> (StatusCode, Json<serde_json::Value>) {
|
|
for error in &payload.errors {
|
|
log::error!(
|
|
"[CLIENT ERROR] {} | {} | {} | URL: {} | Stack: {}",
|
|
error.timestamp,
|
|
error.r#type,
|
|
error.message,
|
|
error.url,
|
|
error.stack.as_deref().unwrap_or("<no stack>")
|
|
);
|
|
}
|
|
|
|
(
|
|
StatusCode::OK,
|
|
Json(serde_json::json!({
|
|
"status": "received",
|
|
"count": payload.errors.len()
|
|
})),
|
|
)
|
|
}
|