DIYgod/RSSHub · error · Error

通知类型${typeParam}未定义

Error message

通知类型${typeParam}未定义

What it means

Thrown by the GDUT OA (Office Automation) news route when the ':type' path parameter does not match any key in the hardcoded typeMap object. The typeMap defines exactly six valid keys: department, academy, notice, announcement, tender_result, tender_invite. The error message includes the invalid type value to aid debugging.

Source

Thrown at lib/routes/gdut/oa-news.ts:87

    maintainers: ['jim-kirisame', 'GamerNoTitle', 'Richard-Zheng'],
    handler,
    url: 'oas.gdut.edu.cn/seeyon',
    description: `学校可能会因为 IP 来源非学校而做出一定的限制,建议在校内网络环境下使用 RSS 阅读器订阅。

| 类型     | 参数           | 可能需要校内访问 |
| -------- | -------------- | ---------------- |
| 部处简讯 | department     | 是               |
| 学院简讯 | academy        | 是               |
| 校内通知 | notice         | 是               |
| 公示公告 | announcement   | 是               |
| 招标结果 | tender\\_result | 否               |
| 招标公告 | tender\\_invite | 否               |`,
};

async function handler(ctx) {
    const typeParam = ctx.req.param('type') ?? 'notice';
    if (typeMap[typeParam] === undefined) {
        throw new Error('通知类型' + typeParam + '未定义');
    }

    const type = typeMap[typeParam];

    // 获取cookie
    const cookieJar = new CookieJar();
    await got(site + '/ggIP.do?method=portalSeachMore&subject=&departmentName=&newsType=&startDate=&endDate=', {
        cookieJar,
    });

    // 获取文章列表
    const listUrl = '/ajax.do?method=ajaxAction&managerName=ggManager&rnd=1';
    const resp = await got.post(site + listUrl, {
        cookieJar,
        form: {
            managerMethod: 'kkFindListDatas',
            arguments: getArg(type),
        },

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the six valid type values: department, academy, notice, announcement, tender_result, tender_invite
  2. Omit the type parameter entirely to default to 'notice'
  3. Refer to the route description table in the source code for the complete mapping

Example fix

// before
const typeParam = ctx.req.param('type') ?? 'notice';
if (typeMap[typeParam] === undefined) {
    throw new Error('通知类型' + typeParam + '未定义');
}

// after (use InvalidParameterError for consistency with RSSHub conventions)
import InvalidParameterError from '@/errors/types/invalid-parameter';
// ...
if (typeMap[typeParam] === undefined) {
    throw new InvalidParameterError(`Invalid type '${typeParam}'. Valid types: ${Object.keys(typeMap).join(', ')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const VALID_TYPES = ['department', 'academy', 'notice', 'announcement', 'tender_result', 'tender_invite'];
const typeParam = ctx.req.param('type') ?? 'notice';
if (!VALID_TYPES.includes(typeParam)) {
    // Return 400 before hitting the handler, or surface a helpful message
    throw new InvalidParameterError(`Invalid type '${typeParam}'. Valid: ${VALID_TYPES.join(', ')}`);
}

Type guard

function isValidType(type: string): type is keyof typeof typeMap {
    return Object.hasOwn(typeMap, type);
}

Prevention

When it happens

Trigger: A request to /gdut/oa_news/<type> where <type> is not one of the six valid keys (e.g., /gdut/oa_news/news, /gdut/oa_news/undefined). The default is 'notice' when no type is provided (ctx.req.param('type') ?? 'notice'), so this only fires when an explicit invalid value is supplied.

Common situations: Typos in the route URL (e.g., 'tendor_result' instead of 'tender_result'); copying an example URL and forgetting to replace a placeholder; using a category name from documentation that changed between versions.

Related errors


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