{"record":{"id":"011981220c8e7a35","repo":"DIYgod/RSSHub","slug":"category-not-found-011981","errorCode":null,"errorMessage":"Category not found","messagePattern":"Category not found","errorType":"exception","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"lib/routes/m-78/news.ts","lineNumber":92,"sourceCode":"    },\n    handler,\n    maintainers: ['KarasuShin'],\n    features: {\n        supportRadar: true,\n    },\n    view: ViewType.Articles,\n};\n\nasync function handler(ctx: Context): Promise<Data> {\n    const rootUrl = 'https://m-78.jp';\n    const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`;\n    const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;\n    const category = ctx.req.param('category') ?? 'news';\n    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')!) : 20;\n\n    const categories = await ofetch(`${cateAPIUrl}?slug=${category}`);\n    if (categories.length === 0) {\n        throw new InvalidParameterError('Category not found');\n    }\n\n    const { id: categoryId, link: categoryLink, name: categoryName } = categories[0];\n\n    const posts = await ofetch<Post[]>(`${postsAPIUrl}?categories=${categoryId}&per_page=${limit}`);\n    return {\n        title: `${categoryName} | ニュース`,\n        link: categoryLink,\n        item: posts.map((post) => {\n            const $ = load(post.content.rendered, null, false);\n            $('#ez-toc-container').remove();\n            $('img').each((_, img) => {\n                if (/wp-content\\/uploads/.test(img.attribs.src)) {\n                    img.attribs.src = img.attribs.src.replace(/(-\\d+x\\d+)/, '');\n                }\n            });\n            return {\n                title: post.title.rendered,","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/m-78/news.ts#L74-L110","documentation":"Thrown by the M-78 news handler (lib/routes/m-78/news.ts:92) as an `InvalidParameterError` when the WordPress REST API at `/wp-json/wp/v2/categories?slug=<category>` returns an empty array — i.e. no WordPress category matches the supplied slug.","triggerScenarios":"Requesting `/m-78/news/<slug>` with a slug that is not a WordPress category on m-78.jp; typo; the category was renamed/removed; uppercase slug (WordPress slugs are lowercase).","commonSituations":"Guessing category names; copying a URL segment that is a tag or page rather than a category; stale slug from an old site structure.","solutions":["Use a valid category slug — confirm via `https://m-78.jp/wp-json/wp/v2/categories`.","Default to `news` if you want the site's main news category.","Ensure the slug is lowercase and hyphenated as WordPress stores it."],"exampleFix":"// before: GET /m-78/news/updates\n// after:  GET /m-78/news  (or a slug confirmed against /wp-json/wp/v2/categories)","handlingStrategy":"validation","validationCode":"async function categoryExists(slug: string): Promise<boolean> {\n    const cats = await ofetch(`https://m-78.jp/wp-json/wp/v2/categories?slug=${encodeURIComponent(slug)}`);\n    return Array.isArray(cats) && cats.length > 0;\n}\nif (!await categoryExists(slug)) throw new TypeError(`Unknown M-78 category '${slug}'`);","typeGuard":"function isWpCategoryArray(v: unknown): v is { id: number; slug: string; link: string; name: string }[] {\n    return Array.isArray(v) && v.length > 0 && typeof v[0]?.id === 'number';\n}","tryCatchPattern":"import { InvalidParameterError } from '@/errors/types/invalid-parameter';\ntry {\n    await fetchM78News(category);\n} catch (e) {\n    if (e instanceof InvalidParameterError && /Category not found/.test(e.message)) {\n        return { error: `No WordPress category '${category}' on m-78.jp` };\n    }\n    throw e;\n}","preventionTips":["Lowercase and hyphenate slugs as WordPress stores them.","Cache the categories list to avoid repeated lookups.","Default to `news` for the common case."],"tags":["invalid-input","route-parameter","wordpress","rest-api"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}