{"record":{"id":"fd9ae9389e0adaa4","repo":"jackwener/OpenCLI","slug":"bilibili-label-api-failed-message-payloa-fd9ae9","errorCode":null,"errorMessage":"Bilibili ${label} API failed: ${message} (${payload.code})","messagePattern":"Bilibili (.+?) API failed: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/summary.js","lineNumber":67,"sourceCode":"        }\n    }\n    try {\n        return await resolveBvid(input);\n    } catch (error) {\n        throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${input}`, error instanceof Error ? error.message : String(error));\n    }\n}\n\nfunction requireOkPayload(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);\n    }\n    if (payload.code !== 0) {\n        const message = payload.message ?? 'unknown error';\n        if (payload.code === -101 || payload.code === -403 || /登录|权限|forbidden|permission|login/i.test(String(message))) {\n            throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);\n        }\n        throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);\n    }\n    return payload.data;\n}\n\nfunction readModelResult(data, bvid) {\n    if (!data || typeof data !== 'object' || Array.isArray(data)) {\n        throw new CommandExecutionError('Bilibili conclusion API returned malformed data');\n    }\n    if (data.code !== 0) {\n        throw new EmptyResultError('bilibili summary', `Bilibili has not generated an AI summary for ${bvid}.`);\n    }\n    let modelResult = data.model_result;\n    if (typeof modelResult === 'string') {\n        try {\n            modelResult = JSON.parse(modelResult);\n        } catch {\n            throw new CommandExecutionError('Bilibili conclusion API returned malformed model_result JSON');\n        }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/summary.js#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait summaryCommand('BV1xx411c7mX'); // typo, API returns code -400\n// after\nawait summaryCommand('BV1xx411c7mD'); // correct id copied from the video page","handlingStrategy":"try-catch","validationCode":"if (!/^BV[A-Za-z0-9]+$/.test(bvid)) throw new Error(`Malformed BV id: ${bvid} (API code -400 will result)`);","typeGuard":"function isBvid(s) {\n  return typeof s === 'string' && /^BV[A-Za-z0-9]+$/.test(s);\n}","tryCatchPattern":"try {\n  const summary = await summaryCommand(bvid);\n} catch (e) {\n  const m = e.message.match(/\\((-?\\d+)\\)\\s*$/);\n  if (m) {\n    const code = Number(m[1]);\n    if (code === -400) console.error('Bad request: check the BV id');\n    else if (code === -404 || code === 62004) console.error('Video not found or deleted');\n    else if (code === 62002) console.error('Video under review or hidden');\n    else throw e;\n    return null;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["api-error","bilibili","business-error","error-code"],"backgroundTag":"api-business-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}