{"record":{"id":"8e8b6c2f543083e5","repo":"jackwener/OpenCLI","slug":"payload-message-payload-code","errorCode":null,"errorMessage":"获取关注列表失败: ${payload.message} (${payload.code})","messagePattern":"获取关注列表失败: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/following.js","lineNumber":29,"sourceCode":"    args: [\n        { name: 'uid', positional: true, required: false, help: '目标用户 ID（默认为当前登录用户）' },\n        { name: 'page', type: 'int', required: false, default: 1, help: '页码' },\n        { name: 'limit', type: 'int', required: false, default: 50, help: '每页数量 (最大 50)' },\n    ],\n    columns: ['mid', 'name', 'sign', 'following', 'fans'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for bilibili following');\n        // 1. Resolve UID (default to self)\n        const uid = kwargs.uid\n            ? await resolveUid(page, kwargs.uid)\n            : await getSelfUid(page);\n        const pn = kwargs.page ?? 1;\n        const ps = Math.min(kwargs.limit ?? 50, 50);\n        // 2. Fetch following list (standard Cookie API, no Wbi signing needed)\n        const payload = await fetchJson(page, `https://api.bilibili.com/x/relation/followings?vmid=${uid}&pn=${pn}&ps=${ps}&order=desc`);\n        if (payload.code !== 0) {\n            throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);\n        }\n        const list = payload.data?.list || [];\n        if (list.length === 0) {\n            return [{ mid: '-', name: `共 ${payload.data?.total ?? 0} 人关注，当前页无数据`, sign: '', following: '', fans: '' }];\n        }\n        // 3. Map to output\n        return list.map((u) => ({\n            mid: u.mid,\n            name: u.uname,\n            sign: (u.sign || '').slice(0, 40),\n            following: u.attribute === 6 ? '互相关注' : '已关注',\n            fans: u.official_verify?.desc || '',\n        }));\n    },\n});\n","sourceCodeStart":11,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/following.js#L11-L45","documentation":"The followings API (api.bilibili.com/x/relation/followings) returned code!==0, so the list could not be fetched; the error surfaces the API's own message and numeric code. Common codes: -400 bad vmid, -403 not-logged-in, -352/-412 risk control, -352 privacy settings.","triggerScenarios":"Querying a uid whose followings list is private, an invalid vmid, an unauthenticated/expired cookie session, or Wbi/risk-control rejection.","commonSituations":"Target user hid their following list (privacy setting), cookies expired mid-script, scraping at high rate triggering -412, or page number beyond the visible range with restricted access.","solutions":["Re-login to refresh cookies if the code indicates auth failure (-101/-403).","If the target hides their list, there is no workaround — use a different uid or inform the user.","Slow down / add delays if -412/-352; retry after waiting.","Validate the uid is numeric and exists before querying."],"exampleFix":"// before\nconst payload = await fetchJson(page, url);\nif (payload.code !== 0) throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);\n// after\nconst payload = await fetchJson(page, url);\nif (payload.code === -101 || payload.code === -403) throw new Error('登录已过期，请重新登录');\nif (payload.code !== 0) throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);","handlingStrategy":"retry","validationCode":"if (!/^\\d+$/.test(String(uid))) throw new Error(`vmid must be numeric: ${uid}`);\nif (!(await isLoggedIn(page))) throw new Error('login required for followings API');","typeGuard":"function isFollowingsPayload(p) {\n  return typeof p === 'object' && p !== null && p.code === 0 && Array.isArray(p.data?.list);\n}","tryCatchPattern":"const payload = await fetchJson(page, url);\nif (payload.code !== 0) {\n  if ([-412, -352].includes(payload.code)) return retryWithBackoff(() => followingCommand(page, kwargs));\n  if ([-101, -403].includes(payload.code)) throw new Error('session expired; re-login required');\n  throw new Error(`cannot list followings of ${uid}: ${payload.message} (${payload.code})`);\n}","preventionTips":["Refresh cookies periodically; -101/-403 means expired session","Throttle requests to avoid -412 risk control","Treat privacy-hidden lists as expected outcomes, not bugs","Pass page/limit within documented bounds (limit <= 50)"],"tags":["bilibili","api-error","network","privacy"],"backgroundTag":"api-error-response-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}