DIYgod/RSSHub · error · Error

Unknown category: ${ctx.req.param('category')}

Error message

Unknown category: ${ctx.req.param('category')}

What it means

Thrown by the Maonan district government route in the default case of a switch statement on the ':category' path parameter. Seven valid categories are defined: zwgk, zwxw, mndt, zdhy, tzgg, zlxx, zcjd. Each maps to a specific path on www.maonan.gov.cn.

Source

Thrown at lib/routes/gov/maonan/maonan.ts:103

            break;
        case 'zdhy':
            id = 'zwxw/zdhy';
            name = '重大会议';
            break;
        case 'tzgg':
            id = 'zwgk/tzgg';
            name = '公告公示';
            break;
        case 'zlxx':
            id = 'zwgk/zlxx';
            name = '招录信息';
            break;
        case 'zcjd':
            id = 'zwgk/zcjd';
            name = '政策解读';
            break;
        default:
            throw new Error(`Unknown category: ${ctx.req.param('category')}`);
    }

    const res = await got(`${host}/${id}/`);
    const dataArray = res.data;
    const $ = load(dataArray);
    const list = $('li.clearfix a[href*="www.maonan.gov.cn"], li.clearfix a[href*="mp.weixin.qq.com"]');

    const items = await Promise.all(
        list.map((i, item) => {
            const $item = $(item);

            const url = new URL($item.attr('href')!);
            const link = url.href;

            const pubDate = timezone(parseDate($('a[href="' + link + '"] ~ .time').text()), 8);

            return cache.tryGet(link, async () => {
                // 获取网页

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the seven valid category codes: zwgk, zwxw, mndt, zdhy, tzgg, zlxx, zcjd
  2. Refer to the route description table for the category-to-code mapping
  3. Use the documented example: /gov/maonan/zwgk

Example fix

// before
default:
    throw new Error(`Unknown category: ${ctx.req.param('category')}`);

// after (use InvalidParameterError for RSSHub consistency)
import InvalidParameterError from '@/errors/types/invalid-parameter';
// ...
default:
    throw new InvalidParameterError(`Unknown category '${ctx.req.param('category')}'. Valid: zwgk, zwxw, mndt, zdhy, tzgg, zlxx, zcjd`);
Defensive patterns

Strategy: validation

Validate before calling

const VALID_CATEGORIES = ['zwgk', 'zwxw', 'mndt', 'zdhy', 'tzgg', 'zlxx', 'zcjd'];
const category = ctx.req.param('category');
if (!VALID_CATEGORIES.includes(category)) {
    throw new InvalidParameterError(`Unknown category '${category}'. Valid: ${VALID_CATEGORIES.join(', ')}`);
}

Type guard

function isValidCategory(cat: string): cat is 'zwgk' | 'zwxw' | 'mndt' | 'zdhy' | 'tzgg' | 'zlxx' | 'zcjd' {
    return ['zwgk', 'zwxw', 'mndt', 'zdhy', 'tzgg', 'zlxx', 'zcjd'].includes(cat);
}

Prevention

When it happens

Trigger: A request to /gov/maonan/:category where the category is not one of the seven valid values. The switch maps each category to an id path and display name; the default throws with the invalid category value.

Common situations: Typo in category (e.g., 'zwg' instead of 'zwgk'); using a category name instead of its code (e.g., '公告公示' instead of 'tzgg'); category was removed or renamed.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/19e989d0492a2b7b. Report an issue: GitHub.