fix: use SELECT 1 for ClickHouse connection test and check response status

This commit is contained in:
t8y2 2026-05-14 20:58:08 +08:00
parent 03e2c0bea1
commit bb766228e6
1 changed files with 6 additions and 2 deletions

View File

@ -71,12 +71,16 @@ async fn ch_query(client: &ChClient, sql: &str, database: Option<&str>) -> Resul
}
pub async fn test_connection(client: &ChClient) -> Result<(), String> {
let url = format!("{}/ping", client.base_url);
let url = format!("{}/?query=SELECT%201", client.base_url);
let req = build_request(client, client.http.get(&url));
with_connection_timeout("ClickHouse", async {
let resp = with_connection_timeout("ClickHouse", async {
req.send().await.map_err(|e| format!("ClickHouse connection failed: {e}"))
})
.await?;
if !resp.status().is_success() {
let body = resp.text().await.unwrap_or_default();
return Err(format!("ClickHouse error: {body}"));
}
Ok(())
}