{"record":{"id":"96215e24684a30ed","repo":"DIYgod/RSSHub","slug":"category-category-not-found","errorCode":null,"errorMessage":"Category \"${category}\" not found","messagePattern":"Category \"(.+?)\" not found","errorType":"exception","errorClass":"InvalidParameterError","httpStatus":503,"severity":"warning","filePath":"lib/routes/tfc-taiwan/category.ts","lineNumber":19,"sourceCode":"import InvalidParameterError from '@/errors/types/invalid-parameter';\nimport type { Route } from '@/types';\nimport ofetch from '@/utils/ofetch';\n\nimport { baseUrl, parseItem, parsePost } from './utils';\n\nconst handler = async (ctx) => {\n    const { category } = ctx.req.param();\n    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : undefined;\n    const isNumericCategory = !Number.isNaN(Number(category));\n\n    const categoryResponse = await ofetch(`${baseUrl}/wp-json/wp/v2/categories${isNumericCategory ? `/${category}` : ''}`, {\n        query: {\n            slug: isNumericCategory ? undefined : category,\n        },\n    });\n\n    if (Array.isArray(categoryResponse) && !categoryResponse.length) {\n        throw new InvalidParameterError(`Category \"${category}\" not found`);\n    }\n    const categoryInfo = isNumericCategory ? categoryResponse : categoryResponse[0];\n    if (!categoryInfo.id) {\n        throw new InvalidParameterError(`Category \"${category}\" not found`);\n    }\n\n    const postsResponse = await parsePost(limit, categoryInfo.id);\n    const items = parseItem(postsResponse);\n\n    return {\n        title: categoryInfo.yoast_head_json.title,\n        description: categoryInfo.yoast_head_json.og_site_name,\n        image: categoryInfo.yoast_head_json.og_image[0].url,\n        logo: categoryInfo.yoast_head_json.og_image[0].url,\n        icon: categoryInfo.yoast_head_json.og_image[0].url,\n        link: categoryInfo.link,\n        lang: 'zh-TW',\n        item: items,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/tfc-taiwan/category.ts#L1-L37","documentation":"First of two category-not-found guards in the TFC Taiwan category route. After querying the WordPress REST API (wp-json/wp/v2/categories) filtered by slug, if the response is an array but empty, the slug matched no category and InvalidParameterError is thrown. This covers the slug-lookup path (isNumericCategory false).","triggerScenarios":"Requesting /tfc-taiwan/category/<slug> where <slug> is non-numeric and does not match any category slug; the REST API returns HTTP 200 with an empty array [] because the slug is unknown.","commonSituations":"Typo in the category slug; the category was renamed/removed; user copied a category name instead of its slug.","solutions":["Verify the slug against GET /wp-json/wp/v2/categories on the TFC Taiwan site and use the exact slug.","Use the numeric category id instead of the slug (the route accepts numeric values).","Confirm the category still exists (it may have been merged/deleted)."],"exampleFix":"// before\nif (Array.isArray(categoryResponse) && !categoryResponse.length) {\n    throw new InvalidParameterError(`Category \"${category}\" not found`);\n}\n\n// after: hint at the lookup endpoint in the message\nif (Array.isArray(categoryResponse) && !categoryResponse.length) {\n    throw new InvalidParameterError(`Category slug \"${category}\" not found. Verify at ${baseUrl}/wp-json/wp/v2/categories`);\n}","handlingStrategy":"validation","validationCode":"async function categorySlugExists(baseUrl: string, slug: string): Promise<boolean> {\n    const r = await ofetch(`${baseUrl}/wp-json/wp/v2/categories`, { query: { slug } });\n    return Array.isArray(r) && r.length > 0;\n}\n// pre-check before calling the handler's fetch","typeGuard":"function isNonEmptyCategoryArray(r: unknown): r is { id: number; slug: string }[] {\n    return Array.isArray(r) && r.length > 0;\n}","tryCatchPattern":"try {\n    return await handler(ctx);\n} catch (e) {\n    if (e instanceof InvalidParameterError && /Category .* not found/.test(e.message)) {\n        return notFound(`Category \"${ctx.req.param('category')}\" does not exist`);\n    }\n    throw e;\n}","preventionTips":["Verify the category slug against /wp-json/wp/v2/categories before subscribing.","Prefer the numeric category id when available to avoid slug-typo failures.","Watch for category renames/deletions on the source site."],"tags":["validation","parameter","wordpress","api-contract"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}