DIYgod/RSSHub · warning · InvalidParameterError

Invalid category

Error message

Invalid category

What it means

Thrown by the Huanqiu (环球网) news route when `isValidHost(category)` returns false for the `:category` path parameter. The handler constructs `https://${category}.huanqiu.com`, so `category` must be a valid DNS subdomain. The `isValidHost` utility does a DNS lookup to confirm `<category>.huanqiu.com` resolves. Documented values are `china`, `world`, `mil`, `taiwai`, `opinion`.

Source

Thrown at lib/routes/huanqiu/index.ts:51

    },
    radar: [
        {
            source: ['huanqiu.com/'],
        },
    ],
    name: '分类',
    maintainers: ['yuxinliu-alex'],
    handler,
    url: 'huanqiu.com/',
    description: `| 国内新闻 | 国际新闻 | 军事 | 台海   | 评论    |
| -------- | -------- | ---- | ------ | ------- |
| china    | world    | mil  | taiwai | opinion |`,
};

async function handler(ctx) {
    const category = ctx.req.param('category') ?? 'china';
    if (!isValidHost(category)) {
        throw new InvalidParameterError('Invalid category');
    }

    const host = `https://${category}.huanqiu.com`;

    const resp = await got({
        method: 'get',
        url: `${host}/api/channel_pc`,
    });

    const name = getKeysRecursive(resp.data.children, 'children', 'domain_name', [])[0];

    const nodes = getKeysRecursive(resp.data.children, 'children', 'node', [])
        .map((x) => `"${x}"`)
        .join(',');
    const req = await got({
        method: 'get',
        url: `${host}/api/list?node=${nodes}&offset=0&limit=${ctx.req.query('limit') ?? 20}`,
    });

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented categories: `china`, `world`, `mil`, `taiwai`, `opinion`.
  2. Verify `<category>.huanqiu.com` resolves via `dig` or `nslookup`.
  3. If deploying behind a restricted DNS, ensure the deployment environment can resolve huanqiu.com subdomains.

Example fix

// before (broken)
// GET /huanqiu/news/taiwan

// after (correct — note the unusual spelling)
// GET /huanqiu/news/taiwai
Defensive patterns

Strategy: validation

Validate before calling

const VALID_CATEGORIES = ['china', 'world', 'mil', 'taiwai', 'opinion'];
function isValidCategory(category: string): boolean {
    return VALID_CATEGORIES.includes(category);
}
// The route uses isValidHost(category) which does DNS resolution.
// Pre-checking against known values is faster and avoids DNS lookups for typos.

Type guard

function isKnownHuanqiuCategory(category: string): category is 'china' | 'world' | 'mil' | 'taiwai' | 'opinion' {
    return ['china', 'world', 'mil', 'taiwai', 'opinion'].includes(category);
}

Prevention

When it happens

Trigger: Requesting `/huanqiu/news/<category>` where `<category>.huanqiu.com` does not resolve in DNS, or where the category string contains invalid hostname characters. Note: the default is `china`, so omitting the parameter is safe.

Common situations: Typo in the category slug (e.g. `taiwai` is easy to misspell as `taiwan`), using a category subdomain that huanqiu does not operate, or DNS resolution failure in the deployment environment.

Related errors


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