DIYgod/RSSHub · warning · Error

Invalid type parameter

Error message

Invalid type parameter

What it means

Thrown by the BUPT (Beijing University of Posts and Telecommunications) jwc route when the `type` parameter is neither 'tzgg' (通知公告) nor 'xwzx' (新闻资讯). Uses an if/else chain ending in a plain `Error` rather than `InvalidParameterError`, so it is reported as a generic failure.

Source

Thrown at lib/routes/bupt/jwc.ts:59

};

async function handler(ctx: Context) {
    let type = ctx.req.param('type'); // 默认类型为通知公告
    if (!type) {
        type = 'tzgg';
    }
    const rootUrl = 'https://jwc.bupt.edu.cn';
    let currentUrl;
    let pageTitle;

    if (type === 'tzgg') {
        currentUrl = `${rootUrl}/tzgg1.htm`;
        pageTitle = '通知公告';
    } else if (type === 'xwzx') {
        currentUrl = `${rootUrl}/xwzx2.htm`;
        pageTitle = '新闻资讯';
    } else {
        throw new Error('Invalid type parameter');
    }

    const response = await got({
        method: 'get',
        url: currentUrl,
    });

    const $ = load(response.data);

    const list = $('.txt-elise')
        .toArray()
        .map((item): (DataItem & { link: string }) | null => {
            const $item = $(item);
            const $link = $item.find('a');
            // Skip elements without links or with empty href
            if ($link.length === 0 || !$link.attr('href')) {
                return null;
            }

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only `/bupt/jwc/tzgg` or `/bupt/jwc/xwzx`.
  2. Maintainers: switch to `InvalidParameterError` and document the two valid values in the route description.

Example fix

// before
throw new Error('Invalid type parameter');
// after
import InvalidParameterError from '@/errors/types/invalid-parameter';
throw new InvalidParameterError("Invalid type parameter. Use 'tzgg' or 'xwzx'");
Defensive patterns

Strategy: validation

Validate before calling

const BUPT_JWC_TYPES = ['tzgg', 'xwzx'] as const;
function validateBuptType(type: string): void {
    if (!(BUPT_JWC_TYPES as readonly string[]).includes(type)) {
        throw new Error(`Invalid type '${type}'. Use 'tzgg' or 'xwzx'.`);
    }
}

Type guard

const BUPT_JWC_TYPES = ['tzgg', 'xwzx'] as const;
type BuptJwcType = typeof BUPT_JWC_TYPES[number];
function isBuptJwcType(v: string): v is BuptJwcType {
    return (BUPT_JWC_TYPES as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Requesting `/bupt/jwc/<type>` with type not equal to 'tzgg' or 'xwzx'. Examples that fail: `/bupt/jwc/jwgg`, `/bupt/jwc/bks`, `/bupt/jwc/`.

Common situations: Confusing this route's type vocabulary with the buct/gr route's, or guessing a category from the jwc.bupt.edu.cn sidebar that is not wired up here.

Related errors


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