jackwener/OpenCLI · error · CommandExecutionError
Bilibili ${label} API failed: ${message} (${payload.code})
Error message
Bilibili ${label} API failed: ${message} (${payload.code}) What it means
This is the general failure branch of requireOkPayload(): the API returned a well-formed envelope with a non-zero code that is not recognized as an auth problem. The Bilibili business error message and numeric code are surfaced verbatim in a CommandExecutionError so the developer can see what the API rejected.
Source
Thrown at clis/bilibili/summary.js:67
}
}
try {
return await resolveBvid(input);
} catch (error) {
throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${input}`, error instanceof Error ? error.message : String(error));
}
}
function requireOkPayload(payload, label) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
}
if (payload.code !== 0) {
const message = payload.message ?? 'unknown error';
if (payload.code === -101 || payload.code === -403 || /登录|权限|forbidden|permission|login/i.test(String(message))) {
throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);
}
throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);
}
return payload.data;
}
function readModelResult(data, bvid) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError('Bilibili conclusion API returned malformed data');
}
if (data.code !== 0) {
throw new EmptyResultError('bilibili summary', `Bilibili has not generated an AI summary for ${bvid}.`);
}
let modelResult = data.model_result;
if (typeof modelResult === 'string') {
try {
modelResult = JSON.parse(modelResult);
} catch {
throw new CommandExecutionError('Bilibili conclusion API returned malformed model_result JSON');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Read the embedded message and code: -400 means fix the BV id; -404/62004 means the video is gone; 62002 means it is under review/hidden.
- Verify the BV id is correct by opening the video in a browser.
- Retry later for transient/rate-limit codes; add delays if batching many videos.
- If a new code appears consistently, check whether the API contract changed.
Example fix
// before
await summaryCommand('BV1xx411c7mX'); // typo, API returns code -400
// after
await summaryCommand('BV1xx411c7mD'); // correct id copied from the video page Defensive patterns
Strategy: try-catch
Validate before calling
if (!/^BV[A-Za-z0-9]+$/.test(bvid)) throw new Error(`Malformed BV id: ${bvid} (API code -400 will result)`); Type guard
function isBvid(s) {
return typeof s === 'string' && /^BV[A-Za-z0-9]+$/.test(s);
} Try / catch
try {
const summary = await summaryCommand(bvid);
} catch (e) {
const m = e.message.match(/\((-?\d+)\)\s*$/);
if (m) {
const code = Number(m[1]);
if (code === -400) console.error('Bad request: check the BV id');
else if (code === -404 || code === 62004) console.error('Video not found or deleted');
else if (code === 62002) console.error('Video under review or hidden');
else throw e;
return null;
}
throw e;
} Prevention
- Validate BV ids with /^BV[A-Za-z0-9]+$/ before calling.
- Check video availability in a browser before batch processing.
- Throttle requests to avoid rate-limit codes.
- Match on the trailing (code) in the message to branch on specific API failures.
When it happens
Trigger: Any non-zero payload.code other than -101/-403 — e.g. -400 (bad request / malformed bvid), -404 (video not found), 62002 (video under review or hidden), 62004 (video deleted), or rate-limit codes returned by view/conclusion endpoints.
Common situations: Typo in the BV id (-400); the video was deleted or made private (-404/62004); the video is pending review (62002); Bilibili API downtime or temporary risk-control rejection with unusual codes.
Related errors
- Bilibili creator comparison API failed: ${message} (${payloa
- 获取视频分P信息失败: ${payload?.message ?? 'unknown'} (${payload?.cod
- 获取关注列表失败: ${payload.message} (${payload.code})
- Bilibili relation query returned a malformed attribute
- 获取视频信息失败: ${view?.message ?? 'unknown'} (${view?.code})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/fd9ae9389e0adaa4.
Report an issue: GitHub.