{"record":{"id":"313ca4d1ef0c91aa","repo":"DIYgod/RSSHub","slug":"error-313ca4","errorCode":null,"errorMessage":"分类不存在","messagePattern":"分类不存在","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/juejin/category.ts","lineNumber":39,"sourceCode":"            source: ['juejin.cn/:category'],\n        },\n    ],\n    name: '分类',\n    maintainers: ['DIYgod'],\n    handler,\n    description: `| 后端    | 前端     | Android | iOS | 人工智能 | 开发工具 | 代码人生 | 阅读    |\n| ------- | -------- | ------- | --- | -------- | -------- | -------- | ------- |\n| backend | frontend | android | ios | ai       | freebie  | career   | article |`,\n};\n\nasync function handler(ctx) {\n    const category = ctx.req.param('category');\n\n    const idResponse = await getCategoryBrief();\n\n    const cat = idResponse.find((item) => item.category_url === category);\n    if (!cat) {\n        throw new Error('分类不存在');\n    }\n    const id = cat.category_id;\n\n    const response = await ofetch('https://api.juejin.cn/recommend_api/v1/article/recommend_cate_feed', {\n        method: 'POST',\n        body: {\n            id_type: 2,\n            sort_type: 300,\n            cate_id: id,\n            cursor: '0',\n            limit: 20,\n        },\n    });\n\n    const list = parseList(response.data);\n    const resultItems = await ProcessFeed(list);\n\n    return {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/juejin/category.ts#L21-L57","documentation":"Thrown by the juejin (掘金) category handler as a plain Error ('分类不存在' = 'category does not exist') when the `category` path param's `category_url` is not found in the list returned by getCategoryBrief(). The handler fetches the full category brief list and searches for a matching slug; no match means it cannot resolve the numeric category_id needed for the recommend feed API.","triggerScenarios":"Request to /juejin/category/<slug> where <slug> is not among the category_url values returned by juejin's category-brief endpoint (e.g. a typo like 'front-end' instead of 'frontend', or a slug that was renamed/removed by 掘金).","commonSituations":"User mistypes the category; 掘金 renames or removes a category slug; new category added upstream but user uses an old/wrong slug; case sensitivity (Backend vs backend).","solutions":["Use one of the documented slugs: backend, frontend, android, ios, ai, freebie, career, article","If 掘金 renamed a slug, call getCategoryBrief() and update the route's description table to the new value","Log idResponse (the full brief list) when debugging to see all valid category_url values","Handle the comparison case-insensitively if 掘金's URLs vary by case"],"exampleFix":"// before\nconst cat = idResponse.find((item) => item.category_url === category);\nif (!cat) {\n    throw new Error('分类不存在');\n}\n// after\nconst cat = idResponse.find((item) => item.category_url?.toLowerCase() === category.toLowerCase());\nif (!cat) {\n    const valid = idResponse.map((i) => i.category_url).filter(Boolean).join(', ');\n    throw new Error(`分类不存在: '${category}'. Valid: ${valid}`);\n}","handlingStrategy":"type-guard","validationCode":"async function categoryExists(slug: string): Promise<boolean> {\n  const briefs = await getCategoryBrief();\n  return briefs.some((i) => i.category_url === slug);\n}\nif (!(await categoryExists(category))) {\n  return ctx.json({ error: `unknown category '${category}'` }, 400);\n}","typeGuard":"interface JuejinBrief { category_url?: string; category_id?: string }\nfunction findCategory(briefs: JuejinBrief[], slug: string): JuejinBrief | undefined {\n  return briefs.find((i) => i.category_url?.toLowerCase() === slug.toLowerCase());\n}","tryCatchPattern":"try { return await handler(ctx); }\ncatch (e) {\n  if (e instanceof Error && e.message === '分类不存在') {\n    return ctx.json({ error: `category '${category}' not found` }, 404);\n  }\n  throw e;\n}","preventionTips":["Cache getCategoryBrief() with a TTL to avoid re-fetching on every validation","Compare slugs case-insensitively if juejin's URLs vary","Surface the list of valid category_url values in the error","Sync the route description table when juejin adds/renames categories"],"tags":["api-response","validation","catalog","parameter"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}