{"record":{"id":"45c411d215d02ec1","repo":"jackwener/OpenCLI","slug":"code-result-code-result-msg-result-m","errorCode":null,"errorMessage":"接口错误 code=${result.code}: ${result.msg || result.message}","messagePattern":"接口错误 code=(.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/hupu/like.js","lineNumber":66,"sourceCode":"                return [{\n                        status: '✅ 点赞成功',\n                        message: ''\n                    }];\n            }\n            else if (result.code === 0 && result.msg === '你已经点亮过这个回帖了') {\n                return [{\n                        status: '⚠️ 已经点赞过了',\n                        message: result.msg || ''\n                    }];\n            }\n            else if (result.code === 0) {\n                return [{\n                        status: '⚠️ 操作未执行',\n                        message: result.msg || result.message || ''\n                    }];\n            }\n            else {\n                throw new Error(`接口错误 code=${result.code}: ${result.msg || result.message}`);\n            }\n        }\n        catch (error) {\n            if (error instanceof CliError)\n                throw error;\n            const errorMessage = error instanceof Error ? error.message : String(error);\n            throw new Error(`点赞失败: ${errorMessage}`);\n        }\n    },\n});\n","sourceCodeStart":48,"sourceCodeEnd":77,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hupu/like.js#L48-L77","documentation":"The hupu like command posts a like/unlike action to Hupu's API and expects result.code === 200. Any other code is treated as a hard API rejection and rethrown as Error with the code plus msg/message from the response, after non-CliError failures fall through the catch block.","triggerScenarios":"Calling the like command for a thread/comment when Hupu's endpoint responds with a non-200 business code — e.g. already-liked, rate-limited, permission denied, or expired auth token embedded in the request.","commonSituations":"Session/token expired so the API returns an auth code; spam/rate limiting after repeated likes; liking content that was deleted; Hupu changing API response codes or field names (msg vs message).","solutions":["Re-authenticate the Hupu session (u cookie/token) — stale auth is the most common cause of non-200 codes","Read the code/msg in the message: 401/403-style codes mean login again; 429-style means slow down","Confirm the target thread/comment still exists before liking","Retry once after a delay for transient codes; avoid rapid repeated like calls"],"exampleFix":"// before\nawait hupuLike(page, tid);\n// after\ntry { await hupuLike(page, tid); }\ncatch (e) {\n  const m = e.message.match(/code=(\\d+)/);\n  if (m && (m[1] === '401' || m[1] === '403')) await hupuLogin(); // refresh session\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const authed = await page.evaluate(() => document.cookie.includes('u='));\nif (!authed) await hupuLogin(page); // avoid auth-code rejections before liking","typeGuard":"function isApiOk(result) { return !!result && result.code === 200; }","tryCatchPattern":"try {\n  await hupuLike(page, tid);\n} catch (e) {\n  const code = Number(e.message.match(/code=(\\d+)/)?.[1]);\n  if (code === 401 || code === 403) await hupuLogin(page);\n  else if (code === 429) await sleep(60000);\n  else throw e;\n}","preventionTips":["Refresh the Hupu session before batch like operations","Throttle like calls to avoid rate-limit codes","Verify the target content exists before liking","Parse and log result.code/msg to react to new codes"],"tags":["api-error","hupu","like","non-200"],"backgroundTag":"api-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}