DIYgod/RSSHub · warning · Error

Invalid type parameter

Error message

Invalid type parameter

What it means

Thrown when the `type` path parameter for the nowcoder hots route is neither '1' (hot topics) nor '2' (hot posts). This is the final fallthrough after both `if (type === '1')` and `if (type === '2')` blocks fail to match. Only the two literal string values are accepted.

Source

Thrown at lib/routes/nowcoder/hots.ts:72

    }
    if (type === '2') {
        link = `https://gw-c.nowcoder.com/api/sparta/hot-search/top-hot-pc?size=${size}&_=${Date.now()}&t=`;
        const responseBody = (await got.get(link)).data;
        if (responseBody.code !== 0) {
            throw new Error(`接口错误,错误代码: ${responseBody.code},错误原因: ${responseBody.msg}`);
        }
        const data = responseBody.data.result;
        return {
            title: '牛客网-全站热贴',
            link: 'https://mnowpick.nowcoder.com/m/discuss/hot',
            description: '牛客网-全站热贴',
            item: data.map((item) => ({
                title: item.title,
                link: `https://www.nowcoder.com/feed/main/detail/${item.uuid}`,
            })),
        };
    }
    throw new Error('Invalid type parameter');
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only type '1' (hot topics) or '2' (hot posts), or omit the parameter entirely to default to '1'.
  2. If Nowcoder added a new hot list type, add a new `if (type === 'N')` block before the throw on line 72.
  3. Replace the final `throw new Error` with `throw new InvalidParametersError` for consistent HTTP 400 semantics.

Example fix

// before
throw new Error('Invalid type parameter');

// after — use InvalidParameterError for correct HTTP 400
import InvalidParameterError from '@/errors/types/invalid-parameter';
// ...
throw new InvalidParameterError(`Invalid type parameter: '${type}'. Supported values: 1 (热议话题), 2 (全站热贴)`);
Defensive patterns

Strategy: validation

Validate before calling

// Validate type before processing
const validTypes = new Set(['1', '2']);
if (!validTypes.has(type)) {
    throw new InvalidParameterError(
        `Invalid type '${type}'. Must be one of: 1 (热议话题), 2 (全站热贴)`
    );
}

Type guard

function isValidHotType(type: string): type is '1' | '2' {
    return type === '1' || type === '2';
}

Prevention

When it happens

Trigger: A user requests `/nowcoder/hots/3`, `/nowcoder/hots/0`, or any type value other than '1' or '2'. Also triggered by typos like `/nowcoder/hots/hot` or numeric variants like `/nowcoder/hots/01`.

Common situations: User misunderstands the route parameter and passes an unsupported type. A radar rule or bookmarked URL references an outdated type value. Automated feed readers cycling through numeric indices hit unsupported values.

Related errors


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