DIYgod/RSSHub · error · InvalidParameterError
Category not found
Error message
Category not found
What it means
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.
Source
Thrown at lib/routes/m-78/news.ts:92
},
handler,
maintainers: ['KarasuShin'],
features: {
supportRadar: true,
},
view: ViewType.Articles,
};
async function handler(ctx: Context): Promise<Data> {
const rootUrl = 'https://m-78.jp';
const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`;
const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;
const category = ctx.req.param('category') ?? 'news';
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')!) : 20;
const categories = await ofetch(`${cateAPIUrl}?slug=${category}`);
if (categories.length === 0) {
throw new InvalidParameterError('Category not found');
}
const { id: categoryId, link: categoryLink, name: categoryName } = categories[0];
const posts = await ofetch<Post[]>(`${postsAPIUrl}?categories=${categoryId}&per_page=${limit}`);
return {
title: `${categoryName} | ニュース`,
link: categoryLink,
item: posts.map((post) => {
const $ = load(post.content.rendered, null, false);
$('#ez-toc-container').remove();
$('img').each((_, img) => {
if (/wp-content\/uploads/.test(img.attribs.src)) {
img.attribs.src = img.attribs.src.replace(/(-\d+x\d+)/, '');
}
});
return {
title: post.title.rendered,View on GitHub (pinned to bed535e087)
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.
Example fix
// before: GET /m-78/news/updates // after: GET /m-78/news (or a slug confirmed against /wp-json/wp/v2/categories)
Defensive patterns
Strategy: validation
Validate before calling
async function categoryExists(slug: string): Promise<boolean> {
const cats = await ofetch(`https://m-78.jp/wp-json/wp/v2/categories?slug=${encodeURIComponent(slug)}`);
return Array.isArray(cats) && cats.length > 0;
}
if (!await categoryExists(slug)) throw new TypeError(`Unknown M-78 category '${slug}'`); Type guard
function isWpCategoryArray(v: unknown): v is { id: number; slug: string; link: string; name: string }[] {
return Array.isArray(v) && v.length > 0 && typeof v[0]?.id === 'number';
} Try / catch
import { InvalidParameterError } from '@/errors/types/invalid-parameter';
try {
await fetchM78News(category);
} catch (e) {
if (e instanceof InvalidParameterError && /Category not found/.test(e.message)) {
return { error: `No WordPress category '${category}' on m-78.jp` };
}
throw e;
} Prevention
- Lowercase and hyphenate slugs as WordPress stores them.
- Cache the categories list to avoid repeated lookups.
- Default to `news` for the common case.
When it happens
Trigger: 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).
Common situations: Guessing category names; copying a URL segment that is a tag or page rather than a category; stale slug from an old site structure.
Related errors
- Invalid category: ${categoryParam}. Valid categories are: ${
- Invalid category: ${category}
- Invalid region
- Invalid Locals content route option. Supported filters are `
- Invalid name
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/011981220c8e7a35.
Report an issue: GitHub.