DIYgod/RSSHub · error · InvalidParameterError
Invalid channel Id: ${id}
Error message
Invalid channel Id: ${id} What it means
Thrown as an InvalidParameterError by the CSRC (China Securities Regulatory Commission) route when the provided channel code (id) is not found in the API's channelLevel response. The route calls getLocalList with channelCode=id, then searches the returned channelLevel array for a matching channelCode. If no match is found, channelId is undefined.
Source
Thrown at lib/routes/gov/csrc/csrc.ts:27
const { id = 'c101972' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 50;
const rootUrl = 'http://www.csrc.gov.cn';
const apiUrl = new URL('getLocalList', rootUrl).href;
const currentUrl = new URL(`/csrc/${id}/zfxxgk_zdgk.shtml`, rootUrl).href;
const { data: channelResponse } = await got(apiUrl, {
searchParams: {
channelCode: id,
},
});
const channel = channelResponse.results.channelLevel.find((channel) => channel.channelCode === id);
const channelId = channel?.channelId ?? undefined;
const channelName = channel?.channelName ?? undefined;
if (!channelId) {
throw new InvalidParameterError(`Invalid channel Id: ${id}`);
}
const apiSearchUrl = new URL(`searchList/${channelId}`, rootUrl).href;
const { data: response } = await got(apiSearchUrl, {
searchParams: {
_isAgg: true,
_isJson: true,
_pageSize: limit,
},
});
const items = response.data.results.slice(0, limit).map((item) => {
const title = item.title;
const description = item.contentHtml;
const enclosure = item.resList?.[0] ?? undefined;
return {View on GitHub (pinned to bed535e087)
Solutions
- Use a valid channel code from the route description table in the source (e.g., c101971 for administrative penalties, c101972 for market ban decisions)
- Omit the id parameter to use the default (c101972)
- Browse www.csrc.gov.cn, navigate to the desired channel, and extract the code from the URL (the part between /csrc/ and /zfxxgk_zdgk.shtml)
Example fix
// before
const channel = channelResponse.results.channelLevel.find((channel) => channel.channelCode === id);
const channelId = channel?.channelId ?? undefined;
if (!channelId) {
throw new InvalidParameterError(`Invalid channel Id: ${id}`);
}
// This is already well-structured. To improve diagnostics:
if (!channelId) {
throw new InvalidParameterError(`Invalid channel Id: ${id}. Valid codes are listed at /gov/csrc/zfxxgk_zdgk route documentation.`);
} Defensive patterns
Strategy: validation
Validate before calling
const VALID_CHANNEL_IDS = ['c101972', 'c101971', 'c101793', 'c101951', 'c101985', /* ... see route description */];
const { id = 'c101972' } = ctx.req.param();
// Best approach: let the API validate. The InvalidParameterError is the API's response.
// For client-side validation, cross-reference the channel code format:
if (!/^c\d{6}$/.test(id)) {
throw new InvalidParameterError(`Channel ID must match format cXXXXXX, got: ${id}`);
} Type guard
function isValidChannelId(id: string): boolean {
return /^c\d{6}$/.test(id);
} Prevention
- Use the default (c101972) when unsure
- Extract channel codes from the CSRC website URL path
- Refer to the extensive channel ID table in the route description
When it happens
Trigger: A request to /gov/csrc/zfxxgk_zdgk/:id where :id (default 'c101972') is not a valid channel code in the CSRC system. The API returns results.channelLevel but none of the entries have a channelCode matching the provided id.
Common situations: Typo in the channel code (e.g., 'c10179' instead of 'c101793'); using an outdated channel code that was removed from the CSRC site; guessing a code format; the channel code format changed on the CSRC site.
Related errors
- Unknown category: ${ctx.req.param('category')}
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Invalid category
- At least one valid search parameter is required
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/0c7bb2715e5ae011.
Report an issue: GitHub.