DIYgod/RSSHub · error · InvalidParameterError

code not supported

Error message

code not supported

What it means

Thrown by swjtu/xg.ts:88 as an InvalidParameterError when listURL[code] is undefined. listURL (line 10) has exactly four keys: tzgg (通知公告), yhxw (扬华新闻), dcxy (多彩学院), xgzj (学工之家). The code param defaults to 'tzgg' when omitted (line 84), so this only fires when an explicit-but-unrecognized code is supplied.

Source

Thrown at lib/routes/swjtu/xg.ts:88

        },
    ],
    name: '扬华素质网',
    maintainers: ['mobyw'],
    handler,
    url: 'xg.swjtu.edu.cn/web/Home/PushNewsList',
    description: `栏目列表:

| 通知公告 | 扬华新闻 | 多彩学院 | 学工之家 |
| -------- | -------- | -------- | -------- |
| tzgg     | yhxw     | dcxy     | xgzj     |`,
};

async function handler(ctx) {
    const code = ctx.req.param('code') ?? 'tzgg';
    const pageURL = listURL[code];

    if (!pageURL) {
        throw new InvalidParameterError('code not supported');
    }

    const resp = await got({
        method: 'get',
        url: pageURL,
    });

    const $ = load(resp.data);
    const list = $('div.right-side ul.block-ctxlist li');

    const items = await Promise.all(
        list.toArray().map((i) => {
            const item = $(i);
            return getItem(item, cache);
        })
    );

    return {

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the four documented codes, lowercase: tzgg, yhxw, dcxy, xgzj.
  2. Omit the code entirely to get the default (tzgg): GET /swjtu/xg.

Example fix

// before
GET /swjtu/xg/tzg
// after
GET /swjtu/xg/tzgg
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_CODES = ['tzgg', 'yhxw', 'dcxy', 'xgzj'] as const;

function isSupportedCode(code: string): boolean {
  return (SUPPORTED_CODES as readonly string[]).includes(code);
}

Type guard

const listURL = {
  tzgg: '...',
  yhxw: '...',
  dcxy: '...',
  xgzj: '...',
} as const;

type SwjtuCode = keyof typeof listURL;

function isSwjtuCode(code: string): code is SwjtuCode {
  return Object.hasOwn(listURL, code);
}

Prevention

When it happens

Trigger: /swjtu/xg/<code> where code is not one of {tzgg, yhxw, dcxy, xgzj}: typos like 'tzg', wrong case ('TZGG'), or a category code the site has but RSSHub does not map.

Common situations: User guesses a category code; the site adds a new column not yet mapped; case mismatch (the keys are lowercase); user passes the Chinese name instead of the code.

Related errors


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