DIYgod/RSSHub · error · InvalidParameterError
Invalid category: . Please refer to the category table in…
Error message
Invalid category: ${category}. Please refer to the category table in the documentation. What it means
InvalidParameterError thrown by the XJTLU news handler when ctx.req.param('category') is not a key of the categories map (all, anniversary, technology, business, environment, humanities, community, about, stories). Object.hasOwn rejects unknown categories before the URL is constructed, preventing 404s on xjtlu.edu.cn.
Solutions
- Use one of the documented category keys (all, anniversary, technology, business, environment, humanities, community, about, stories).
- Omit the category segment to fall back to the 'all' default.
- If the site added a section, add it to the categories map and rebuild.
Defensive patterns
Strategy: validation
Validate before calling
const CATEGORY_KEYS = new Set(Object.keys(categories));
function resolveCategory(raw: string | undefined): keyof typeof categories {
const category = raw ?? 'all';
if (!CATEGORY_KEYS.has(category)) {
throw new InvalidParameterError(`Invalid category "${category}". Valid: ${[...CATEGORY_KEYS].join(', ')}`);
}
return category as keyof typeof categories;
} Type guard
function isXjtluCategory(value: string): value is keyof typeof categories {
return Object.hasOwn(categories, value);
} Prevention
- Derive the allow-list from the categories object itself so it stays in sync.
- Default to 'all' when the segment is omitted.
- Re-check the categories map if XJTLU restructures its news sections.
When it happens
Trigger: A request to /xjtlu/news/:lang/:category with a category string that is not one of the nine defined keys, e.g. /xjtlu/news/en/research or a typo like 'tech' instead of 'technology'.
Common situations: Caller guessed a category name not in the route docs; XJTLU restructured news sections and a previously valid key was removed; user passed an empty-but-defined category that is not 'all'.
Related errors
- Invalid language parameter. Use "en" or "zh".
- Invalid keyword
- Invalid rank type
- Invalid type
- Invalid type: . Supported types
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/f668304888ea20e0.
Report an issue: GitHub.
Appendix: source
Thrown at lib/routes/xjtlu/news.ts:60
},
stories: {
en: { name: 'XJTLU Stories', path: 'news/xjtlu-stories' },
zh: { name: '招生专区', path: 'news_category/topictopic4683' },
},
};
const handler = async (ctx) => {
const lang = ctx.req.param('lang') ?? 'en';
const category = ctx.req.param('category') ?? 'all';
// Validate language parameter
if (lang !== 'en' && lang !== 'zh') {
throw new InvalidParameterError('Invalid language parameter. Use "en" or "zh".');
}
// Validate category parameter
if (!Object.hasOwn(categories, category)) {
throw new InvalidParameterError(`Invalid category: ${category}. Please refer to the category table in the documentation.`);
}
// Build the list URL based on category
const baseUrl = `https://www.xjtlu.edu.cn/${lang}`;
const categoryPath = categories[category][lang].path;
const listUrl = `${baseUrl}/${categoryPath}`;
// Fetch the news list page
const response = await ofetch(listUrl);
const $ = load(response);
// Extract article cards from the page
const list = $('.card-group-3 .card.up-down-card, .content .card.up-down-card')
.toArray()
.map((item) => {
const $item = $(item);
const link = $item.find('.a-links-block').attr('href');
const title = $item.find('.card-title').text().trim();View on GitHub (pinned to bed535e087)