jackwener/OpenCLI · error

接口错误 code=${result.code}: ${result.msg || result.message}

Error message

接口错误 code=${result.code}: ${result.msg || result.message}

What it means

Thrown by the hupu reply CLI when postHupuJson returns a response whose code is not 1 (Hupu's success code) for the createReply API. It is a plain Error carrying the API's business code and message (result.msg || result.message). After this throw, the outer catch re-wraps it as '回复失败: 接口错误 code=...'.

Source

Thrown at clis/hupu/reply.js:62

            content,
            shumeiId: '',
            deviceid: '',
            tid
        };
        // 如果有引用回复ID,添加到请求体
        if (quote_id) {
            body.quoteId = quote_id;
        }
        try {
            const result = await postHupuJson(page, tid, url, body, 'Reply to Hupu thread', 'reply');
            if (result.code === 1) {
                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

  1. Read code and msg in the message: fix the identified issue (wrong tid/topic_id, banned content, permissions).
  2. Verify tid is a valid 9-digit thread ID and topic_id matches the thread's board (e.g. 502 for basketball news).
  3. Re-authenticate: ensure the browser session is logged in to bbs.hupu.com with valid cookies.
  4. If content was rejected, reword the reply to avoid Hupu keyword/moderation filters.
  5. Slow down if rate-limited; wait before retrying.

Example fix

// before: failing call with mismatched board
$ opencli hupu reply 631234567 " nice" --topic_id 999
Error: 回复失败: 接口错误 code=40002: 板块不匹配

// after: use the thread's real board id
$ opencli hupu reply 631234567 "nice" --topic_id 502
✅ 回复成功
Defensive patterns

Strategy: validation

Validate before calling

// Validate inputs before calling hupu reply
if (!/^\d{9}$/.test(String(tid))) throw new Error('tid must be a 9-digit thread ID');
if (!String(topic_id).trim()) throw new Error('topic_id (board id, e.g. 502) is required and must match the thread\'s board');
if (!String(text).trim()) throw new Error('reply text must not be empty');
// Optionally pre-check thread exists:
const page = await fetch(`https://bbs.hupu.com/${tid}.html`);
if (!page.ok) throw new Error(`Thread ${tid} not accessible (HTTP ${page.status}) — cannot reply`);

Type guard

function isApiSuccess(result) {
  return result !== null && typeof result === 'object' && result.code === 1;
}

Try / catch

try {
  await run('hupu reply', { _: [tid, text], topic_id });
} catch (e) {
  const m = String(e.message).match(/接口错误 code=(\S+): (.*)/);
  if (m) console.error(`Hupu rejected reply (code ${m[1]}): ${m[2]} — check tid/topic_id, login, and content policy`);
  else throw e;
}

Prevention

When it happens

Trigger: Calling 'hupu reply <tid> <text> --topic_id <id>' when Hupu's createReply rejects the request: wrong/nonexistent tid or topic_id, content blocked by moderation/keyword filters, not logged in or cookie invalid, duplicate reply, or account restricted from posting.

Common situations: Passing a topic_id that does not match the thread's board; replying to a locked or deleted thread; reply text hitting Hupu content filters; posting too frequently and being rate-limited; expired login cookies.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1c8569503ce5ba7b. Report an issue: GitHub.