DIYgod/RSSHub · warning · InvalidParameterError

Invalid language

Error message

Invalid language

What it means

Thrown by the KPMG insights route when the :lang path parameter does not match a key in the endpoints map, which only contains 'en' and 'zh'. The route default is 'en', so this only fires when a user explicitly supplies an unsupported language code.

Source

Thrown at lib/routes/kpmg/insights.tsx:84

            <>
                <br />
                {raw(content)}
            </>
        ) : null}
        {pdf ? (
            <>
                <br />
                {raw(pdf)}
            </>
        ) : null}
    </>
);

const handler = async (ctx: Context) => {
    const { lang = 'en' } = ctx.req.param();
    const endpoint = endpoints[lang];
    if (!endpoint) {
        throw new InvalidParameterError('Invalid language');
    }
    const link = endpoint.link;

    const response = await ofetch(endpoint.api, {
        method: 'POST',
        body: payload,
    });

    const list = response.results.map((item) => ({
        title: item.kpmg_title.raw,
        description: item.kpmg_description.raw,
        link: item.kpmg_url.raw,
        pubDate: parseDate(item.kpmg_article_date_time.raw),
        image: item.kpmg_image.raw,
        imageAlt: item.kpmg_image_alt?.raw,
    }));

    const item = await Promise.all(

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only 'en' or 'zh' — these are the two configured endpoints.
  2. Normalize the input with lang.toLowerCase() before lookup to handle case-insensitive input.
  3. Include the valid options in the error message: throw new InvalidParameterError(`Invalid language '${lang}'. Supported: en, zh`).
  4. To add a language, add an entry to the endpoints object with title/link/api and it will be automatically accepted.

Example fix

// before
const { lang = 'en' } = ctx.req.param();
const endpoint = endpoints[lang];
if (!endpoint) throw new InvalidParameterError('Invalid language');

// after — case-insensitive + helpful message
const { lang = 'en' } = ctx.req.param();
const normalized = lang.toLowerCase();
const endpoint = endpoints[normalized as keyof typeof endpoints];
if (!endpoint) {
    throw new InvalidParameterError(`Invalid language '${lang}'. Supported: ${Object.keys(endpoints).join(', ')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const validLangs = Object.keys(endpoints); // ['en', 'zh']
const { lang = 'en' } = ctx.req.param();
const normalized = lang.toLowerCase();
if (!validLangs.includes(normalized)) {
    throw new InvalidParameterError(`Invalid language '${lang}'. Supported: ${validLangs.join(', ')}`);
}

Type guard

function isKpmgLang(lang: string): lang is keyof typeof endpoints {
    return lang in endpoints;
}

Prevention

When it happens

Trigger: Calling /kpmg/insights/ja, /kpmg/insights/fr, or any lang value other than 'en'/'zh'. Also fires for case mismatches like 'EN' or 'Zh' since the lookup is case-sensitive with no normalization.

Common situations: User assumes more languages are supported (KPMG has many regional sites). User passes an uppercase or mixed-case code. A typo in the URL. The route needs a new language but the endpoints map and this check were not updated together.

Related errors


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