DIYgod/RSSHub · error · InvalidParameterError

Invalid type: ${type}

Error message

Invalid type: ${type}

What it means

An InvalidParameterError thrown when the :type path segment is not one of the keys in the shiep config object. The config object enumerates every supported subdomain/section (news, xxgk, zs, career, …); an unknown type cannot be mapped to a host, so the route rejects it before any network call.

Source

Thrown at lib/routes/shiep/index.tsx:61

| -------------------- | ---------- | ---------- | ------ | ------ | ------ | ------ | ------ | -------------------------------- | --------------- | ------ | -------- | -------------------------- | ------------------ | ------ | ------------------------ | ------- | ------------------------- | -------------------- | --------------------- | ---------------- | ------------ |
| office               | dwllc      | fzghc      | sjc    | bwc    | xsc    | rsc    | tgb    | fao                              | kyc             | jwc    | yjsc     | hqglc                      | sysyzcglc          | jjc    | lgxq                     | library | metc                      | ieetc                | cyb                   | kczx             | jszyzx       |
| 389                  | 2649       | 291        | 199    | tzgg   | 3482   | 1695   | notice | tzgg                             | 834             | 227    | 1161     | 1616                       | 312                | 327    | 377                      | 4866    | tzgg                      | cxcy                 | 367                   | 3946             | 4247         |

其它:

| 新闻网 | 信息公开网 | 本科招生网 | 本科就业信息网 | 文明办  | 学习路上 | “学条例 守党纪” 专题网 | 上海新能源人才技术教育交流中心 | 上海绿色能源并网技术研究中心 | 能源电力智库 | 智能发电实验教学中心 |
| ------ | ---------- | ---------- | -------------- | ------- | -------- | ---------------------- | ------------------------------ | ---------------------------- | ------------ | -------------------- |
| news   | xxgk       | zs         | career         | wenming | ztjy     | xxjy                   | gec                            | green-energy                 | nydlzk       | spgc                 |
| notice | zxgkxx     | zxxx       | tzgg           | 2202    | 5575     | 5973                   | 1959                           | 118                          | tzgg         | 4449                 |

参数与来源页面对应规则为:\`https://\${type}.shiep.edu.cn/\${id}/list.htm\``,
};

async function handler(ctx) {
    const type = ctx.req.param('type');

    if (!Object.keys(config).includes(type)) {
        throw new InvalidParameterError(`Invalid type: ${type}`);
    }

    const { listSelector = '.list_item', pubDateSelector = '.Article_PublishDate', descriptionSelector = '.wp_articlecontent', title } = config[type];

    if (!title) {
        throw new InvalidParameterError(`Invalid type: ${type}`);
    }

    const host = `https://${type}.shiep.edu.cn`;
    const id = ctx.req.param('id') || config[type].id;
    const link = type === 'career' ? `${host}/news/index/tag/${id}` : `${host}/${id}/list.htm`;

    const response = await got(link);
    const $ = load(response.data);

    const list = $(listSelector)
        .toArray()
        .map((item): DataItem & { link: string } => {

View on GitHub (pinned to bed535e087)

Solutions

  1. Consult the route description table (lib/routes/shiep/index.tsx lines 28-52) and use a documented type value.
  2. If the section genuinely exists but is missing from config, add it to ./config with the correct id, host, and selectors.
  3. Use the InvalidParameterError's 400-class behavior so subscribers see a clear bad-input response.

Example fix

// before
if (!Object.keys(config).includes(type)) {
    throw new InvalidParameterError(`Invalid type: ${type}`);
}

// after — list the valid types in the error so the caller can self-correct
const VALID_TYPES = Object.keys(config);
if (!VALID_TYPES.includes(type)) {
    throw new InvalidParameterError(`Invalid type: ${type}. Valid types: ${VALID_TYPES.join(', ')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const VALID_TYPES = Object.keys(config);
if (!VALID_TYPES.includes(type)) {
    throw new InvalidParameterError(`Invalid type: ${type}. Valid types: ${VALID_TYPES.join(', ')}`);
}

Type guard

const isValidShiepType = (t: string): t is keyof typeof config =>
    Object.prototype.hasOwnProperty.call(config, t);

Prevention

When it happens

Trigger: ctx.req.param('type') returns a value that is not a key of the config object imported from ./config, so `!Object.keys(config).includes(type)` is true. The user requested a subdomain/section that the route was never configured for.

Common situations: A typo in the type segment (e.g. 'new' instead of 'news'); using an old section name after the site reorganized; requesting a subdomain that exists on shiep.edu.cn but was never added to the config table.

Related errors


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