{"record":{"id":"59ad8d3b71dc0b15","repo":"DIYgod/RSSHub","slug":"tieba-api-error-data-error-msg-data-error-co","errorCode":null,"errorMessage":"Tieba API error: ${data.error_msg || data.error_code}","messagePattern":"Tieba API error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/baidu/tieba/forum.tsx","lineNumber":58,"sourceCode":"            text += item.text;\n        } else if (Number(item.type) === 3) {\n            const src = item.origin_src || item.original_src || item.big_cdn_src || item.cdn_src || item.src;\n            if (src) {\n                images.push(src);\n            }\n        }\n    }\n    return { text, images };\n}\n\nasync function handler(ctx) {\n    const { kw, cid = '0', sortBy = 'created' } = ctx.req.param();\n    const isGood = ctx.req.path.includes('good');\n\n    const data = await getTiebaForumData({ kw, cid, isGood, sortBy });\n\n    if (data?.error_code && data.error_code !== '0' && data.error_code !== 0) {\n        throw new Error(`Tieba API error: ${data.error_msg || data.error_code}`);\n    }\n\n    const threadList = data?.thread_list || [];\n\n    if (threadList.length === 0) {\n        throw new Error('No threads found. The cookie may be expired or invalid. Please check your BAIDU_COOKIE.');\n    }\n\n    // Build author map from user_list\n    const userList: any[] = data?.user_list || [];\n    const authorMap = new Map<number, string>();\n    for (const user of userList) {\n        if (user.id) {\n            authorMap.set(Number(user.id), user.name_show || user.name || '');\n        }\n    }\n\n    const list = threadList.map((thread) => {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/baidu/tieba/forum.tsx#L40-L76","documentation":"The Tieba forum route inspects the API response for a non-zero error_code and throws an Error containing error_msg (or error_code as fallback). This surfaces upstream Baidu errors (rate limiting, invalid signature, bad parameters, anti-spam) rather than silently rendering an empty feed.","triggerScenarios":"getTiebaForumData returns a payload with error_code that is neither '0' nor 0 - e.g. expired/invalid cookie signature, blocked keyword (kw), missing cid, or Baidu's anti-crawler returning an error_code.","commonSituations":"BAIDU_COOKIE expired or revoked; the queried forum name (kw) is banned/renamed; running from an IP that Baidu has throttled; sending requests without the headers/signature the API now expects.","solutions":["Refresh BAIDU_COOKIE by re-logging in to tieba.baidu.com and copying fresh cookies.","Verify the forum keyword (kw) exists and is not blocked.","Slow down requests if the error code indicates rate limiting; retry after a backoff.","Check the error_msg text in the thrown message - it usually names the specific failure."],"exampleFix":"// before\nBAIDU_COOKIE=expired_value\n// after\nBAIDU_COOKIE=freshly_copied_cookie_string","handlingStrategy":"try-catch","validationCode":"function isTiebaApiOk(data: any): boolean {\n  return !data || data.error_code === 0 || data.error_code === '0';\n}\nif (!isTiebaApiOk(data)) throw new Error(`Tieba API error: ${data.error_msg || data.error_code}`);","typeGuard":"const isTiebaApiSuccess = (d: any): boolean =>\n  d == null || d.error_code === 0 || d.error_code === '0' || d.error_code === undefined;","tryCatchPattern":"try {\n  return await handler(ctx);\n} catch (e) {\n  if (e instanceof Error && /Tieba API error/.test(e.message)) {\n    // refresh cookie and retry once\n    return await handler(ctx);\n  }\n  throw e;\n}","preventionTips":["Keep BAIDU_COOKIE fresh; set up an alert on this error to catch expiry early.","Rate-limit Tieba requests to avoid anti-crawler error codes.","Log the error_msg verbatim - it identifies the specific upstream failure."],"tags":["baidu-tieba","api","cookie","rss-route"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}