jlcodes99/cockpit-tools · error

网关 {} 请求失败[{}]: {} (url={})

Error message

网关 {} 请求失败[{}]: {} (url={})

What it means

post_gateway_json performs a reqwest POST to a gateway operation endpoint; when the request fails at the transport layer (send().await errors) it is classified via classify_gateway_transport_error and wrapped as '网关 {op} 请求失败[{kind}]: {err} (url={url})'. This is a request never got a valid HTTP response — DNS, connect, TLS, or timeout-level failure.

Source

Thrown at src-tauri/src/modules/wakeup.rs:749

    client: &reqwest::Client,
    url: &str,
    body: &serde_json::Value,
    op_name: &str,
    cancel_rx: Option<&watch::Receiver<bool>>,
) -> Result<serde_json::Value, String> {
    let resp = await_with_cancel(
        cancel_rx,
        client
            .post(url)
            .header(reqwest::header::CONTENT_TYPE, "application/json")
            .json(body)
            .send(),
    )
    .await?
    .map_err(|e| {
        let kind = classify_gateway_transport_error(&e);
        let message = format!("网关 {} 请求失败[{}]: {} (url={})", op_name, kind, e, url);
        crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
        message
    })?;

    let status = resp.status();
    let text = await_with_cancel(cancel_rx, resp.text())
        .await?
        .unwrap_or_default();
    if !status.is_success() {
        crate::modules::logger::log_error(&format!(
            "[Wakeup] 网关 {} 返回错误: url={}, status={}, body_len={}, body={}",
            op_name,
            url,
            status,
            summarize_body_len(&text),
            truncate_log_text(&text, 512)
        ));
        return Err(format!(
            "网关 {} 返回错误: status={}, body_len={}",

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Check the [kind] in the message (dns/connect/tls/timeout) to target the fix
  2. Verify the gateway URL/base configuration is correct and reachable (curl the url)
  3. Check local network: VPN, proxy, firewall, DNS settings
  4. Retry — the caller chain supports fallback base URLs and retry attempts
  5. If TLS-related, update/repair CA certificates or fix the gateway's certificate

Example fix

// before
.map_err(|e| {
    let kind = classify_gateway_transport_error(&e);
    let message = format!("网关 {} 请求失败[{}]: {} (url={})", op_name, kind, e, url);
    crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
    message
})?;
// after
.map_err(|e| {
    let kind = classify_gateway_transport_error(&e);
    let message = format!("网关 {} 请求失败[{}]: {} (url={})", op_name, kind, e, url);
    crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
    if matches!(kind, TransportErrorKind::Timeout | TransportErrorKind::Connect) {
        // caller falls back to next base URL
    }
    message
})?;
Defensive patterns

Strategy: retry

Validate before calling

// Reachability pre-check before posting to the gateway
fn gateway_reachable(url: &str) -> bool {
    reqwest::blocking::get(url).map(|r| r.status().is_success()).unwrap_or(false)
}
if !gateway_reachable(&gateway_base) { eprintln!("gateway unreachable: {}", gateway_base); }

Type guard

fn is_gateway_transport_error(err: &str) -> bool { err.contains("请求失败[") }

Try / catch

match trigger_wakeup_via_client_gateway(req).await {
    Err(e) if e.contains("请求失败[") => {
        // transport-level: exponential backoff, then try next base URL
        for base in fallback_base_urls() {
            if try_wakeup(base).await.is_ok() { break; }
        }
    }
    other => handle(other),
}

Prevention

When it happens

Trigger: trigger_wakeup_via_client_gateway_once → post_gateway_json with an unreachable gateway host, refused connection, TLS failure, or client timeout before a response arrives.

Common situations: Gateway offline or wrong base URL configured; local network/VPN/proxy blocking the host; DNS resolution failure; TLS cert expired or self-signed; corporate firewall; server overloaded refusing connections.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/1bb18592ac9efc7e. Report an issue: GitHub.