DIYgod/RSSHub · warning · Error

Invalid category

Error message

Invalid category

What it means

Generic Error validating the category path parameter of /blizzard/news-cn/:category? against the categoryNames map (ow, hs, wow). It prevents constructing a rootUrl from an unknown game subdomain and a downstream parser miss. The check uses Object.hasOwn for an exact-key lookup.

Source

Thrown at lib/routes/blizzard/news-cn.ts:117

function getList(category, $) {
    return Object.hasOwn(parsers, category) ? parsers[category]($) : [];
}

async function fetchDetail(item, category) {
    return await cache.tryGet(item.link, async () => {
        const response = await ofetch(item.link);
        const $ = load(response);

        const parseDetail = detailParsers[category];
        item.description = parseDetail($);
        return item;
    });
}

async function handler(ctx) {
    const category = ctx.req.param('category') || 'ow';
    if (!Object.hasOwn(categoryNames, category)) {
        throw new Error('Invalid category');
    }

    const rootUrl = `https://${category}.blizzard.cn/news`;

    const response = await ofetch(rootUrl);
    const $ = load(response);

    const list = getList(category, $);
    if (!list.length) {
        throw new Error('No news found');
    }

    const items = await Promise.all(list.map((item) => fetchDetail(item, category)));

    return {
        title: `${categoryNames[category]}新闻`,
        link: rootUrl,
        item: items,

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the supported abbreviations: ow (Overwatch), hs (Hearthstone), wow (World of Warcraft).
  2. Omit the category to default to ow.
  3. To add a game, extend categoryNames, parsers, and detailParsers and submit a PR.

Example fix

// before
if (!Object.hasOwn(categoryNames, category)) {
    throw new Error('Invalid category');
}
// after (name the valid keys)
if (!Object.hasOwn(categoryNames, category)) {
    throw new Error(`Invalid category: ${category}. Valid: ${Object.keys(categoryNames).join(', ')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const category = ctx.req.param('category') || 'ow';
if (!Object.hasOwn(categoryNames, category)) {
    throw new Error(`Invalid category '${category}'. Valid: ${Object.keys(categoryNames).join(', ')}`);
}

Type guard

type BlizzardCategory = keyof typeof categoryNames;
const isBlizzardCategory = (c: string): c is BlizzardCategory =>
    Object.hasOwn(categoryNames, c);

Prevention

When it happens

Trigger: A request with a category value that is not a key of categoryNames (e.g. 'overwatch', 'hots', 'd3', or a typo). The hasOwn check fails before any HTTP call.

Common situations: Using the full game name instead of the abbreviation; requesting a Blizzard game not covered (Heroes of the Storm, Diablo); URL typo.

Related errors


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