{"record":{"id":"68fb2e6b8f8ae213","repo":"DIYgod/RSSHub","slug":"invalid-language-lang","errorCode":null,"errorMessage":"Invalid language: ${lang}","messagePattern":"Invalid language: (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":503,"severity":"warning","filePath":"lib/routes/ea/apex-news.ts","lineNumber":26,"sourceCode":"import { parseDate } from '@/utils/parse-date';\n\nconst md = MarkdownIt({\n    html: true,\n    breaks: true,\n});\n\nconst langEnum = new Set(['zh-hant', 'en']);\nconst typeEnum = new Set(['latest', 'game-updates', 'news-article']);\n\nasync function handler(ctx) {\n    const { lang = 'en', type = 'latest' } = ctx.req.param();\n    const apiParams = new URLSearchParams({\n        limit: '13',\n        gameSlug: 'apex-legends',\n        offset: '0',\n    });\n    if (!langEnum.has(lang)) {\n        throw new InvalidParameterError(`Invalid language: ${lang}`);\n    }\n    if (!typeEnum.has(type)) {\n        throw new InvalidParameterError(`Invalid type: ${type}`);\n    }\n    if (type !== 'latest') {\n        apiParams.append('typeSlug', type);\n    }\n    if (lang !== 'en') {\n        apiParams.append('locale', lang);\n    }\n    const apiUrl = `https://drop-api.ea.com/news-articles/pagination?${apiParams}`;\n    const newsItems = await ofetch(apiUrl);\n\n    type NewsItem = DataItem & {\n        slug: string;\n    };\n    const allItems: NewsItem[] = [newsItems.featured, ...newsItems.items].filter(Boolean).map((item) => ({\n        title: item.title,","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/ea/apex-news.ts#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate lang before the handler logic\nconst SUPPORTED_LANGS = new Set(['zh-hant', 'en']);\nfunction validateLang(lang: string | undefined): string {\n    const resolved = lang ?? 'en';\n    if (!SUPPORTED_LANGS.has(resolved)) {\n        throw new InvalidParameterError(`Invalid language: ${lang}. Supported: en, zh-hant`);\n    }\n    return resolved;\n}","typeGuard":"function isSupportedLang(lang: string): lang is 'en' | 'zh-hant' {\n    return lang === 'en' || lang === 'zh-hant';\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["parameter-validation","enum-check","invalid-parameter-error"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}