{"record":{"id":"370481059f7663ae","repo":"jackwener/OpenCLI","slug":"bilibili-creator-comparison-api-failed-message","errorCode":null,"errorMessage":"Bilibili creator comparison API failed: ${message} (${payload.code})","messagePattern":"Bilibili creator comparison API failed: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/creator-stats.js","lineNumber":57,"sourceCode":"    return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isAuthLike(code, message) {\n    return code === -101\n        || code === -111\n        || /登录|账号未登录|login required|not logged in/i.test(String(message ?? ''));\n}\n\nfunction requirePayload(payload) {\n    if (!isRecord(payload) || !Number.isSafeInteger(payload.code)) {\n        throw new CommandExecutionError('Bilibili creator comparison API returned a malformed envelope');\n    }\n    const message = String(payload.message ?? payload.msg ?? 'unknown error');\n    if (payload.code !== 0) {\n        if (isAuthLike(payload.code, message)) {\n            throw new AuthRequiredError('member.bilibili.com', `Bilibili creator-center login is required: ${message}`);\n        }\n        throw new CommandExecutionError(`Bilibili creator comparison API failed: ${message} (${payload.code})`);\n    }\n    if (!isRecord(payload.data) || !Array.isArray(payload.data.list)) {\n        throw new CommandExecutionError('Bilibili creator comparison API returned malformed list data');\n    }\n    return payload.data.list;\n}\n\nasync function fetchComparison(page) {\n    try {\n        const payload = await page.fetchJson(\n            `${MEMBER_ORIGIN}/x/web/data/archive_diagnose/compare?size=100`,\n            { timeoutMs: FETCH_TIMEOUT_SECONDS * 1000 },\n        );\n        return requirePayload(payload);\n    }\n    catch (error) {\n        if (\n            error instanceof AuthRequiredError","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/creator-stats.js#L39-L75","documentation":"Generic failure branch of requirePayload: the envelope is well formed but `code` is a non-zero value that is not auth-like. The Bilibili message (payload.message/msg) and numeric code are surfaced verbatim in a CommandExecutionError. Because this endpoint is undocumented, arbitrary negative Bilibili codes (rate-limit, permission, internal) land here.","triggerScenarios":"fetchJson on archive_diagnose/compare returns e.g. {code: -412, message: '请求被拦截'} or {code: -403, ...} — any business error other than -101/-111 or login-text messages.","commonSituations":"Bilibili rate-limiting or risk-control blocking the request (-412); account lacking permission for the analytics scope; transient Bilibili server errors (-500); endpoint deprecated or moved on the server side.","solutions":["Read the numeric code and Chinese message in the error to identify the Bilibili business error and act on it (e.g. -412 → slow down / wait, then retry)","Retry after a backoff if the code indicates rate limiting or a transient server error","Verify the account still has creator-center access for the requested analytics","If the code persists, check whether Bilibili changed/retired the undocumented compare endpoint"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const rows = await runCommand();\n} catch (e) {\n  const m = /\\((\\-?\\d+)\\)$/.exec(e.message);\n  const code = m ? Number(m[1]) : null;\n  if (code === -412) { /* rate limited: back off exponentially and retry */ }\n  else if (code === -403) { /* permission: check account scope */ }\n  else throw e;\n}","preventionTips":["Space out requests to Bilibili's creator-center endpoints to avoid -412 risk control","Parse the numeric code from the '(code)' suffix for targeted handling","Monitor Bilibili API status; transient 5xx-style codes clear on retry","Keep the account in good standing with creator-center access"],"tags":["bilibili","api-error","rate-limit","remote-api"],"backgroundTag":"bilibili-api-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}