DIYgod/RSSHub · warning · InvalidParameterError
Category "${category}" not found
Error message
Category "${category}" not found What it means
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).
Source
Thrown at lib/routes/tfc-taiwan/category.ts:19
import InvalidParameterError from '@/errors/types/invalid-parameter';
import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { baseUrl, parseItem, parsePost } from './utils';
const handler = async (ctx) => {
const { category } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : undefined;
const isNumericCategory = !Number.isNaN(Number(category));
const categoryResponse = await ofetch(`${baseUrl}/wp-json/wp/v2/categories${isNumericCategory ? `/${category}` : ''}`, {
query: {
slug: isNumericCategory ? undefined : category,
},
});
if (Array.isArray(categoryResponse) && !categoryResponse.length) {
throw new InvalidParameterError(`Category "${category}" not found`);
}
const categoryInfo = isNumericCategory ? categoryResponse : categoryResponse[0];
if (!categoryInfo.id) {
throw new InvalidParameterError(`Category "${category}" not found`);
}
const postsResponse = await parsePost(limit, categoryInfo.id);
const items = parseItem(postsResponse);
return {
title: categoryInfo.yoast_head_json.title,
description: categoryInfo.yoast_head_json.og_site_name,
image: categoryInfo.yoast_head_json.og_image[0].url,
logo: categoryInfo.yoast_head_json.og_image[0].url,
icon: categoryInfo.yoast_head_json.og_image[0].url,
link: categoryInfo.link,
lang: 'zh-TW',
item: items,View on GitHub (pinned to bed535e087)
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).
Example fix
// before
if (Array.isArray(categoryResponse) && !categoryResponse.length) {
throw new InvalidParameterError(`Category "${category}" not found`);
}
// after: hint at the lookup endpoint in the message
if (Array.isArray(categoryResponse) && !categoryResponse.length) {
throw new InvalidParameterError(`Category slug "${category}" not found. Verify at ${baseUrl}/wp-json/wp/v2/categories`);
} Defensive patterns
Strategy: validation
Validate before calling
async function categorySlugExists(baseUrl: string, slug: string): Promise<boolean> {
const r = await ofetch(`${baseUrl}/wp-json/wp/v2/categories`, { query: { slug } });
return Array.isArray(r) && r.length > 0;
}
// pre-check before calling the handler's fetch Type guard
function isNonEmptyCategoryArray(r: unknown): r is { id: number; slug: string }[] {
return Array.isArray(r) && r.length > 0;
} Try / catch
try {
return await handler(ctx);
} catch (e) {
if (e instanceof InvalidParameterError && /Category .* not found/.test(e.message)) {
return notFound(`Category "${ctx.req.param('category')}" does not exist`);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Typo in the category slug; the category was renamed/removed; user copied a category name instead of its slug.
Related errors
- Category "${category}" not found
- Bad timeRange range. See <a href="https://docs.rsshub.app/ro
- Bad parameter. See <a href="https://docs.rsshub.app/routes/g
- Invalid city
- Invalid channel name
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/96215e24684a30ed.
Report an issue: GitHub.