DIYgod/RSSHub · warning · InvalidParameterError
Bad category. See <a href="https://docs.rsshub.app/routes/go
Error message
Bad category. See <a href="https://docs.rsshub.app/routes/government#guang-dong-sheng-ren-min-zheng-fu-shen-zhen-shi-zhu-fang-he-jian-she-ju">docs</a>
What it means
Thrown by RSSHub's Shenzhen Housing and Construction Bureau route handler when the `:caty` path parameter does not match any key in the local `config` object. The `config` object at lib/routes/gov/shenzhen/zjj/index.ts:9 defines exactly one entry: `tzgg` (通知公告). RSSHub's `InvalidParameterError` serializes to an HTTP 400 response and renders the message as HTML, which is why the message contains an `<a>` tag linking to the docs.
Source
Thrown at lib/routes/gov/shenzhen/zjj/index.ts:46
},
radar: [
{
source: ['zjj.sz.gov.cn/xxgk/:caty'],
},
],
name: '住房和建设局',
maintainers: ['lonn'],
handler,
description: `| 通知公告 |
| :------: |
| tzgg |`,
};
async function handler(ctx) {
const baseUrl = 'http://zjj.sz.gov.cn/xxgk/';
const cfg = config[ctx.req.param('caty')];
if (!cfg) {
throw new InvalidParameterError('Bad category. See <a href="https://docs.rsshub.app/routes/government#guang-dong-sheng-ren-min-zheng-fu-shen-zhen-shi-zhu-fang-he-jian-she-ju">docs</a>');
}
const currentUrl = new URL(cfg.link, baseUrl).href;
const { data: response } = await got(currentUrl);
const $ = load(response);
const items = $('div.listcontent_right ul li')
// 使用“toArray()”方法将选择的所有 DOM 元素以数组的形式返回。
.toArray()
// 使用“map()”方法遍历数组,并从每个元素中解析需要的数据。
.map((item) => {
const $item = $(item);
const a = $item.find('a');
return {
title: a.text(),
// `link` 需要一个绝对 URL,但 `a.attr('href')` 返回一个相对 URL。
link: a.attr('href'),View on GitHub (pinned to bed535e087)
Solutions
- Use `/gov/shenzhen/zjj/xxgk/tzgg` — it is the sole valid category.
- If additional categories are needed, confirm the corresponding sub-page exists under `zjj.sz.gov.cn/xxgk/`, then add an entry to the `config` object with the correct relative `link` path and `title`.
Example fix
// before (broken URL) // GET /gov/shenzhen/zjj/xxgk/notice // after (correct URL) // GET /gov/shenzhen/zjj/xxgk/tzgg
Defensive patterns
Strategy: validation
Validate before calling
const VALID_CATEGORIES = ['tzgg'] as const;
function validateCategory(caty: string | undefined): caty is typeof VALID_CATEGORIES[number] {
return (VALID_CATEGORIES as readonly string[]).includes(caty ?? '');
}
// Usage in handler:
// if (!validateCategory(ctx.req.param('caty'))) {
// throw new InvalidParameterError(`Bad category. Valid: ${VALID_CATEGORIES.join(', ')}`);
// } Type guard
function isValidZjjCategory(caty: string): caty is 'tzgg' {
return caty === 'tzgg';
} Prevention
- Document the single valid value (`tzgg`) prominently in the route description.
- Consider using route-level regex constraints (e.g. `/zjj/xxgk/:caty(tzgg)`) to reject invalid values before they reach the handler.
- Keep the config object and the description table in sync when adding or removing categories.
When it happens
Trigger: Requesting `/gov/shenzhen/zjj/xxgk/<value>` where `<value>` is anything other than `tzgg`. The handler does `config[ctx.req.param('caty')]` and any missing key yields `undefined`, tripping the guard at line 45.
Common situations: User copies a category slug from a sibling Shenzhen gov sub-route (e.g. zzb's `rqgs`, `zcfg`, `gzdt`), mistypes the category, or follows outdated documentation listing categories that were removed or never added. The route description table only shows `tzgg`.
Related errors
- pattern not matched
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Nanjing, Cannot find page
- Bad category. See <a href="https://docs.rsshub.app/routes/go
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/08393b6e59b45215.
Report an issue: GitHub.