{"record":{"id":"344f917ef3444751","repo":"jlcodes99/cockpit-tools","slug":"status-body-len","errorCode":null,"errorMessage":"网关 {} 返回错误: status={}, body_len={}","messagePattern":"网关 (.+?) 返回错误: status=(.+?), body_len=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/modules/wakeup.rs","lineNumber":767,"sourceCode":"        crate::modules::logger::log_error(&format!(\"[Wakeup] {}\", message));\n        message\n    })?;\n\n    let status = resp.status();\n    let text = await_with_cancel(cancel_rx, resp.text())\n        .await?\n        .unwrap_or_default();\n    if !status.is_success() {\n        crate::modules::logger::log_error(&format!(\n            \"[Wakeup] 网关 {} 返回错误: url={}, status={}, body_len={}, body={}\",\n            op_name,\n            url,\n            status,\n            summarize_body_len(&text),\n            truncate_log_text(&text, 512)\n        ));\n        return Err(format!(\n            \"网关 {} 返回错误: status={}, body_len={}\",\n            op_name,\n            status,\n            summarize_body_len(&text)\n        ));\n    }\n\n    serde_json::from_str::<serde_json::Value>(&text).map_err(|e| {\n        let message = format!(\"网关 {} 响应解析失败: {} (url={})\", op_name, e, url);\n        crate::modules::logger::log_error(&format!(\n            \"[Wakeup] {}，body_len={}\",\n            message,\n            summarize_body_len(&text)\n        ));\n        message\n    })\n}\n\nasync fn resolve_requested_model_for_official_ls(","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/modules/wakeup.rs#L749-L785","documentation":"post_gateway_json received an HTTP response but with an error status; it logs details (url, status, body length, truncated body) and returns '网关 {op} 返回错误: status={}, body_len={}'. The gateway answered, but the operation failed server-side (4xx client error or 5xx server error).","triggerScenarios":"trigger_wakeup_via_client_gateway_once → post_gateway_json gets status outside 2xx, e.g. 400 from a malformed request payload, 401/403 auth failure at the gateway, 429 rate limiting, or 5xx gateway crash/overload.","commonSituations":"Expired gateway session/token; request schema changed after a gateway version update; payload exceeding limits; 429 rate limiting under heavy wakeup traffic; gateway deployment broken (5xx).","solutions":["Check `status` in the message: 4xx → fix request/auth; 5xx → server-side, retry later","Inspect the truncated body in logs for the gateway's error detail","Refresh gateway credentials/session if 401/403","Back off and retry on 429/5xx (the code marks retryable = 429 or >=500)","Compare request payload against the gateway API version — update the client if schema drifted"],"exampleFix":"// before\nreturn Err(format!(\"网关 {} 返回错误: status={}, body_len={}\", op_name, status, summarize_body_len(&text)));\n// after\nlet retryable = status == reqwest::StatusCode::TOO_MANY_REQUESTS || status.as_u16() >= 500;\nreturn Err(format!(\"网关 {} 返回错误: status={}, retryable={}, body_len={}\",\n    op_name, status, retryable, summarize_body_len(&text)));","handlingStrategy":"retry","validationCode":"// Validate payload shape and auth before calling the gateway op\nfn precheck(payload: &serde_json::Value, token: &str) -> Result<(), String> {\n    if token.is_empty() { return Err(\"missing gateway session token\".into()); }\n    if payload.get(\"op\").is_none() { return Err(\"payload missing 'op'\".into()); }\n    Ok(())\n}","typeGuard":"fn is_gateway_http_error(err: &str) -> bool { err.contains(\"返回错误: status=\") }","tryCatchPattern":"let retryable = |e: &str| e.contains(\"status=429\") || {\n    e.split(\"status=\").nth(1).and_then(|s| s.split(',').next())\n     .and_then(|s| s.parse::<u16>().ok()).map_or(false, |c| c >= 500)\n};\nmatch post_gateway_json(...).await {\n    Err(e) if is_gateway_http_error(&e) && retryable(&e) => retry_with_backoff().await,\n    Err(e) if is_gateway_http_error(&e) => eprintln!(\"non-retryable gateway error: {}\", e),\n    other => handle(other),\n}","preventionTips":["Retry only on 429/5xx with exponential backoff and jitter","Log the truncated response body (as the code does) for every non-2xx","Keep request payloads aligned with the gateway API version; add schema tests","Refresh gateway credentials when 401/403 appears"],"tags":["gateway","http-error","api-response","network"],"backgroundTag":"gateway-http-error-response","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}