{"record":{"id":"2fdc256d38028f84","repo":"DIYgod/RSSHub","slug":"response-message-error-code-response-code","errorCode":null,"errorMessage":"response.message ?? `Error code ${response.code}`","messagePattern":"response\\.message \\?\\? `Error code (.+?)`","errorType":"exception","errorClass":null,"httpStatus":503,"severity":"error","filePath":"lib/routes/bilibili/message-at.ts","lineNumber":105,"sourceCode":"    const cookie = config.bilibili.cookies[uid];\n    if (cookie === undefined) {\n        throw new ConfigNotFoundError('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值');\n    }\n\n    const response = await ofetch<AtResponse>('https://api.bilibili.com/x/msgfeed/at', {\n        query: {\n            platform: 'web',\n            build: 0,\n            mobi_app: 'web',\n        },\n        headers: {\n            Referer: 'https://message.bilibili.com/',\n            Cookie: cookie,\n        },\n    });\n\n    if (response.code !== 0) {\n        throw new Error(response.message ?? `Error code ${response.code}`);\n    }\n\n    const items: DataItem[] = (response.data.items || []).map((item) => {\n        const atUser = item.user;\n        const atItem = item.item;\n        const sourceContent = atItem.source_content;\n\n        let description = `<p><strong>${atUser.nickname}</strong> @了你：</p>`;\n        description += `<blockquote>${sourceContent}</blockquote>`;\n\n        if (atItem.image) {\n            description += `<p><img src=\"${atItem.image.replace('http://', 'https://')}\" /></p>`;\n        }\n\n        description += `<p>来自：${atItem.business} - ${atItem.title}</p>`;\n\n        // Generate link with root_id for direct navigation\n        let link = atItem.uri;","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/message-at.ts#L87-L123","documentation":"Generic Error thrown by the message-at route when Bilibili's /x/msgfeed/at API returns a non-zero code. The error message is response.message if present, otherwise a formatted 'Error code N' string. This fires after a successful authenticated request but when Bilibili returns an error payload (e.g., rate limiting, session issues, or API changes).","triggerScenarios":"The msgfeed/at endpoint returns response.code !== 0 despite a valid cookie being attached. Possible codes: -101 (not logged in / cookie issues at a sub-service level), -509 (rate limited), -7 (account restricted), or temporary backend errors.","commonSituations":"Polling the mentions feed too frequently; cookie partially expired (SESSDATA present but DedeUserID mismatch); Bilibili added new requirements to the msgfeed endpoint; account flagged for API automation.","solutions":["Inspect the response.code and response.message to identify the specific Bilibili error.","If -101 or -6, refresh the cookie via browser re-login.","If -509, reduce polling frequency and increase cache expiry.","If the error persists, verify the msgfeed API hasn't changed by testing the endpoint manually."],"exampleFix":"// before\nif (response.code !== 0) {\n    throw new Error(response.message ?? `Error code ${response.code}`);\n}\n\n// after: include actionable context\nif (response.code !== 0) {\n    const hint = response.code === -101 ? ' (cookie may be expired — refresh BILIBILI_COOKIE)'\n        : response.code === -509 ? ' (rate limited — reduce frequency)'\n        : '';\n    throw new Error(`msgfeed/at error ${response.code}: ${response.message ?? 'unknown'}${hint}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"interface BilibiliApiResponse {\n    code: number;\n    message?: string;\n    data?: unknown;\n}\n\nfunction isApiError(response: BilibiliApiResponse): boolean {\n    return response.code !== 0;\n}","tryCatchPattern":"try {\n    const response = await ofetch<AtResponse>(url, {...});\n    if (response.code !== 0) {\n        const hint = response.code === -101 ? ' (refresh cookie)'\n            : response.code === -509 ? ' (rate limited)'\n            : '';\n        throw new Error(`${response.message ?? `code ${response.code}`}${hint}`);\n    }\n} catch (e) {\n    logger.error(`msgfeed/at failed: ${e.message}`);\n    throw e;\n}","preventionTips":["Inspect the code value to distinguish cookie vs rate-limit issues.","Cache msgfeed results to reduce API calls.","Handle -509 with exponential backoff.","Log full error context for diagnosis."],"tags":["bilibili","messages","api-error","rate-limiting","rsshub"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}