{"record":{"id":"8f7441054af67008","repo":"BigPizzaV3/CodexPlusPlus","slug":"ret-errcode","errorCode":null,"errorMessage":"微信长轮询被拒绝：ret={} errcode={} {}","messagePattern":"微信长轮询被拒绝：ret=(.+?) errcode=(.+?) (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/connect/weixin.rs","lineNumber":239,"sourceCode":"                    ret: 0,\n                    errcode: 0,\n                    errmsg: String::new(),\n                    messages: Vec::new(),\n                    get_updates_buf: get_updates_buf.to_string(),\n                    longpolling_timeout_ms: timeout_ms,\n                });\n            }\n            Err(error) => return Err(error).context(\"微信长轮询请求失败\"),\n        };\n        let (http_status, bytes) =\n            read_response_limited(response, MAX_API_RESPONSE_BYTES, \"微信长轮询\").await?;\n        if !http_status.is_success() {\n            bail!(\"微信长轮询请求失败：HTTP {http_status}\");\n        }\n        let updates: WeixinUpdates =\n            serde_json::from_slice(&bytes).context(\"微信长轮询响应格式无效\")?;\n        if updates.ret != 0 || updates.errcode != 0 {\n            bail!(\n                \"微信长轮询被拒绝：ret={} errcode={} {}\",\n                updates.ret,\n                updates.errcode,\n                updates.errmsg\n            );\n        }\n        Ok(updates)\n    }\n\n    pub async fn send_text_chunks(\n        &self,\n        to_user_id: &str,\n        text: &str,\n        context_token: &str,\n    ) -> anyhow::Result<()> {\n        if context_token.trim().is_empty() {\n            bail!(\"微信回复缺少 context_token\");\n        }","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/connect/weixin.rs#L221-L257","documentation":"Even with HTTP 200, the WeChat long-poll body carries an application-level result code; get_updates deserializes WeixinUpdates and requires ret == 0 and errcode == 0, otherwise bailing with this message that embeds ret, errcode and errmsg. This distinguishes WeChat-side business rejections (auth, kicked session, invalid params) from transport errors.","triggerScenarios":"Calling get_updates when the WeChat API responds 200 with a non-zero ret or errcode — typically an invalid/expired token, the session being kicked by another login, or malformed request parameters.","commonSituations":"User re-logged-in on another device invalidating this session; token rotated and the old one still in use; WeChat-side parameter/API change reflected in errmsg; account restrictions.","solutions":["Read errmsg in the message — it names the WeChat-side cause (e.g. invalid session, kicked)","Re-run the QR login flow to obtain a fresh token and restart the bridge","Check errmsg against current WeChat API docs for schema/param changes","Stop the poll loop instead of hot-retrying on persistent non-zero ret to avoid lockouts"],"exampleFix":"// before\nlet updates = client.get_updates(&token, &cursor).await?; // bails on ret!=0, loop spins\n// after\nlet updates = client.get_updates(&token, &cursor).await.map_err(|e| {\n    if e.to_string().contains(\"微信长轮询被拒绝\") {\n        anyhow!(\"会话失效({e:#})，需重新扫码登录\")\n    } else { e }\n})?;","handlingStrategy":"try-catch","validationCode":"// nothing to pre-validate: ret/errcode are server-side; parse defensively\nlet updates: WeixinUpdates = serde_json::from_slice(&bytes)?;\nlet ok = updates.ret == 0 && updates.errcode == 0;","typeGuard":"fn updates_accepted(u: &WeixinUpdates) -> bool { u.ret == 0 && u.errcode == 0 }","tryCatchPattern":"match get_updates(&token, &cursor).await {\n    Err(e) if e.to_string().contains(\"微信长轮询被拒绝\") => {\n        let msg = e.to_string();\n        if msg.contains(\"token\") || msg.contains(\"kicked\") { restart_login(); } else { log_and_pause(); }\n    }\n    other => other?,\n}","preventionTips":["Parse errmsg and branch on known WeChat business codes","Stop/re-login on persistent rejections instead of hot-retrying","Keep the token in sync with logins from other devices","Track WeChat API changelogs for ret/errcode semantics"],"tags":["wechat","api","long-polling","auth"],"backgroundTag":"api-error-response","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}