DIYgod/RSSHub · warning · InvalidParameterError
Invalid language: ${lang}
Error message
Invalid language: ${lang} What it means
Thrown as an `InvalidParameterError` when the `lang` path parameter is not in the allowed set `{'zh-hant', 'en'}`. RSSHub's InvalidParameterError produces an HTTP 400-level response so the user knows the input is wrong, not the server. This is pre-flight validation before any network call.
Source
Thrown at lib/routes/ea/apex-news.ts:26
import { parseDate } from '@/utils/parse-date';
const md = MarkdownIt({
html: true,
breaks: true,
});
const langEnum = new Set(['zh-hant', 'en']);
const typeEnum = new Set(['latest', 'game-updates', 'news-article']);
async function handler(ctx) {
const { lang = 'en', type = 'latest' } = ctx.req.param();
const apiParams = new URLSearchParams({
limit: '13',
gameSlug: 'apex-legends',
offset: '0',
});
if (!langEnum.has(lang)) {
throw new InvalidParameterError(`Invalid language: ${lang}`);
}
if (!typeEnum.has(type)) {
throw new InvalidParameterError(`Invalid type: ${type}`);
}
if (type !== 'latest') {
apiParams.append('typeSlug', type);
}
if (lang !== 'en') {
apiParams.append('locale', lang);
}
const apiUrl = `https://drop-api.ea.com/news-articles/pagination?${apiParams}`;
const newsItems = await ofetch(apiUrl);
type NewsItem = DataItem & {
slug: string;
};
const allItems: NewsItem[] = [newsItems.featured, ...newsItems.items].filter(Boolean).map((item) => ({
title: item.title,View on GitHub (pinned to bed535e087)
Solutions
- Use one of the two supported values: `en` (English) or `zh-hant` (Traditional Chinese).
- Omit the lang parameter entirely to default to `en`.
- Check the route definition's `parameters.lang.options` for the authoritative list of valid values.
Defensive patterns
Strategy: validation
Validate before calling
// Validate lang before the handler logic
const SUPPORTED_LANGS = new Set(['zh-hant', 'en']);
function validateLang(lang: string | undefined): string {
const resolved = lang ?? 'en';
if (!SUPPORTED_LANGS.has(resolved)) {
throw new InvalidParameterError(`Invalid language: ${lang}. Supported: en, zh-hant`);
}
return resolved;
} Type guard
function isSupportedLang(lang: string): lang is 'en' | 'zh-hant' {
return lang === 'en' || lang === 'zh-hant';
} Prevention
- Always check the route's parameter options before constructing the URL.
- Default to the most common language ('en') when the parameter is omitted.
- Document valid values prominently in the route description.
When it happens
Trigger: A user requests `/ea/apex-news/<lang>/...` where `<lang>` is something other than `zh-hant` or `en` — for example `zh`, `zh-cn`, `ja`, or a typo like `enf`. The langEnum Set check fails immediately.
Common situations: User guesses a language code (e.g., `zh` instead of `zh-hant`, or `cn` instead of `en`). Documentation or third-party feed readers pass an unsupported locale. A URL encoding issue mangles the parameter.
Related errors
- Invalid type: ${type}
- No category '${category}'.
- Bad category. See <a href="https://docs.rsshub.app/routes/ne
- Invalid host
- Invalid user name
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/68fb2e6b8f8ae213.
Report an issue: GitHub.