{"record":{"id":"2556f531e084e862","repo":"DIYgod/RSSHub","slug":"error-code-response-data-code-message","errorCode":null,"errorMessage":"Error code ${response.data.code}: ${message}","messagePattern":"Error code (.+?): (.+?)","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/routes/bilibili/watchlater.ts","lineNumber":60,"sourceCode":"    const embed = !ctx.req.param('embed');\n    const name = await cache.getUsernameFromUID(uid);\n\n    const cookie = config.bilibili.cookies[uid];\n    if (cookie === undefined) {\n        throw new ConfigNotFoundError('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值');\n    }\n\n    const response = await got({\n        method: 'get',\n        url: 'https://api.bilibili.com/x/v2/history/toview',\n        headers: {\n            Referer: `https://space.bilibili.com/${uid}/`,\n            Cookie: cookie,\n        },\n    });\n    if (response.data.code) {\n        const message = response.data.code === -6 ? '对应 uid 的 Bilibili 用户的 Cookie 已过期' : response.data.message;\n        throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);\n    }\n    const list = response.data.data.list || [];\n\n    const out = list.map((item) => ({\n        title: item.title,\n        description: utils.renderUGCDescription(embed, item.pic, `${item.desc}<br><a href=\"https://www.bilibili.com/list/watchlater?bvid=${item.bvid}\">在稍后再看列表中查看</a>`, item.aid, undefined, item.bvid),\n        pubDate: parseDate(item.add_at * 1000),\n        link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,\n        author: item.owner.name,\n    }));\n\n    return {\n        title: `${name} 稍后再看`,\n        link: 'https://www.bilibili.com/watchlater#/list',\n        item: out,\n    };\n}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/watchlater.ts#L42-L78","documentation":"ConfigNotFoundError thrown when Bilibili's /x/v2/history/toview API returns a non-zero code. It is mapped to ConfigNotFoundError (not a generic Error) because the two dominant causes — code -6 (cookie expired) and other auth failures — are configuration problems. The message embeds the raw code and a human-readable hint.","triggerScenarios":"The watch-later request reaches the API with a cookie present, but the API responds with code -6 (login expired), -101 (not logged in), -403 (access denied), or any other non-zero status. The handler maps -6 to 'Cookie 已过期' and otherwise uses response.data.message.","commonSituations":"The SESSDATA in the configured cookie has expired (Bilibili sessions rotate); only a partial cookie was stored (missing SESSDATA); the cookie belongs to a different account than the uid; Bilibili temporarily rate-limits the endpoint.","solutions":["Re-log in to bilibili.com and update BILIBILI_COOKIE_{uid} with a fresh full Cookie header.","Ensure SESSDATA, bili_jct, and DedeUserID are all present in the stored cookie string.","If the code is not -6, read response.data.message in the logs to identify the specific API rejection and act on it.","Verify the cookie was captured from the same account as the route uid."],"exampleFix":"// before\nthrow new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);\n// after (surface the exact API message + hint to refresh cookie)\nthrow new ConfigNotFoundError(`Error code ${response.data.code}: ${message}. Re-login and update BILIBILI_COOKIE_${uid}.`);","handlingStrategy":"validation","validationCode":"if (response.data.code) {\n    const expired = response.data.code === -6;\n    const message = expired ? 'Cookie expired' : response.data.message;\n    throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);\n}","typeGuard":"const isApiErrorCode = (data: any): boolean =>\n    typeof data?.code === 'number' && data.code !== 0;","tryCatchPattern":"try {\n    const resp = await got({ ... });\n    if (resp.data.code) throw new ConfigNotFoundError(`Error code ${resp.data.code}`);\n} catch (e) {\n    if (e instanceof ConfigNotFoundError) throw e; // surface auth/config issues to the user\n    throw new Error('watchlater request failed: ' + (e as Error).message);\n}","preventionTips":["Refresh BILIBILI_COOKIE_{uid} proactively before SESSDATA expiry.","Store the full Cookie string (SESSDATA + bili_jct + DedeUserID), not just SESSDATA.","Log the exact non-zero code so transient vs auth failures are distinguishable."],"tags":["bilibili","authentication","cookie-expired","config","api-error"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}