jackwener/OpenCLI · error
接口错误 code=${result.code}: ${result.msg || result.message}
Error message
接口错误 code=${result.code}: ${result.msg || result.message} What it means
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.
Source
Thrown at clis/hupu/like.js:66
return [{
status: '✅ 点赞成功',
message: ''
}];
}
else if (result.code === 0 && result.msg === '你已经点亮过这个回帖了') {
return [{
status: '⚠️ 已经点赞过了',
message: result.msg || ''
}];
}
else if (result.code === 0) {
return [{
status: '⚠️ 操作未执行',
message: result.msg || result.message || ''
}];
}
else {
throw new Error(`接口错误 code=${result.code}: ${result.msg || result.message}`);
}
}
catch (error) {
if (error instanceof CliError)
throw error;
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`点赞失败: ${errorMessage}`);
}
},
});
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await hupuLike(page, tid);
// after
try { await hupuLike(page, tid); }
catch (e) {
const m = e.message.match(/code=(\d+)/);
if (m && (m[1] === '401' || m[1] === '403')) await hupuLogin(); // refresh session
else throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const authed = await page.evaluate(() => document.cookie.includes('u='));
if (!authed) await hupuLogin(page); // avoid auth-code rejections before liking Type guard
function isApiOk(result) { return !!result && result.code === 200; } Try / catch
try {
await hupuLike(page, tid);
} catch (e) {
const code = Number(e.message.match(/code=(\d+)/)?.[1]);
if (code === 401 || code === 403) await hupuLogin(page);
else if (code === 429) await sleep(60000);
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- 点赞失败: ${errorMessage}
- Read Hupu mentions failed: ${result.error || 'unknown error'
- 接口错误 code=${result.code}: ${result.msg || result.message}
- 接口错误 code=${result.code}: ${result.msg || result.message}
- ${probe.detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/45c411d215d02ec1.
Report an issue: GitHub.