DIYgod/RSSHub · warning · Error

Unknown type: ${type}

Error message

Unknown type: ${type}

What it means

A plain Error thrown by the Nanjing Normal University (CEAI) route when the `type` path param does not match one of the switch cases (xygg / xyxw / xszx). It is a user-input validation guard, but uses a generic Error rather than InvalidParameterError, so it surfaces as a 500 rather than a 400.

Source

Thrown at lib/routes/njnu/ceai/ceai.ts:47

async function handler(ctx) {
    const type = ctx.req.param('type');
    let title, path;
    switch (type) {
        case 'xygg':
            title = '学院公告';
            path = '1651';
            break;
        case 'xyxw':
            title = '学院新闻';
            path = '1652';
            break;
        case 'xszx':
            title = '学生资讯';
            path = '1659';
            break;
        default:
            throw new Error(`Unknown type: ${type}`);
    }
    const base = 'http://ceai.njnu.edu.cn/Item/List.asp?ID=' + path;

    const response = await got(base);

    const $ = load(response.data);

    const list = $('span a').toArray();

    const result = await util.ProcessFeed(list, cache);

    return {
        title: '南京师范大学计电人院 - ' + title,
        link: 'http://ceai.njnu.edu.cn/',
        description: '南京师范大学计电人院',
        item: result,
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented type values: xygg (学院公告), xyxw (学院新闻), xszx (学生资讯).
  2. Prefer throwing InvalidParameterError so RSSHub returns a 400 with a clear message instead of a 500.
  3. If you maintain the route, consider a Map lookup with a single validation point like the njust routes.

Example fix

// before
default:
    throw new Error(`Unknown type: ${type}`);

// after
default:
    throw new InvalidParameterError(`Unknown type: ${type}. Valid: xygg, xyxw, xszx`);
Defensive patterns

Strategy: validation

Validate before calling

const VALID = new Set(['xygg','xyxw','xszx']);
function buildCeaiUrl(type) {
  if (!VALID.has(type)) throw new Error(`Unknown type '${type}'. Valid: ${[...VALID].join(', ')}`);
  return 'http://ceai.njnu.edu.cn/Item/List.asp?ID=' + MAP[type];
}

Type guard

const isCeaiType = (t: string): t is 'xygg'|'xyxw'|'xszx' => VALID.has(t);

Prevention

When it happens

Trigger: Calling /njnu/ceai/:type with a type outside {xygg, xyxw, xszx} — typos, unknown codes, or assumed category names. The switch has no graceful default.

Common situations: User mistypes the category code; user guesses a code; documentation drift between the route description and the switch cases.

Related errors


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