DIYgod/RSSHub · warning · InvalidParameterError

Invalid id

Error message

Invalid id

What it means

Thrown by the jiemian (界面新闻) account handler as InvalidParameterError when the `id` path parameter (from /account/main/:id) is not a key of categoryMap. The map only contains '1' (财经号), '2' (城市号), '3' (媒体号), so any other value triggers this. Because categoryMap is keyed by string, a numeric 1 vs '1' also matters.

Source

Thrown at lib/routes/jiemian/account.ts:34

export const route: Route = {
    path: '/account/main/:id',
    parameters: { id: '分类 id,见下表,可在对应分类页 URL 中找到' },
    name: '界面号',
    example: '/jiemian/account/main/1',
    maintainers: ['nczitzk', 'pseudoyu'],
    handler,
    description: `| [财经号](https://www.jiemian.com/account/main/1.html) | [城市号](https://www.jiemian.com/account/main/2.html) | [媒体号](https://www.jiemian.com/account/main/3.html) |
| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- |
| 1                                                     | 2                                                     | 3                                                     |`,
};

async function handler(ctx: Context): Promise<Data> {
    const { id } = ctx.req.param();
    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 10;

    const category = categoryMap[id];
    if (!category) {
        throw new InvalidParameterError('Invalid id');
    }

    const response = await ofetch<string>('https://papi.jiemian.com/page/api/officialAccount/get_index_lists', {
        query: {
            ckey: category.ckey,
            page: 1,
        },
    });

    const list = JSON.parse(response.slice(response.indexOf('(') + 1, response.lastIndexOf(')')))
        .result.slice(0, limit)
        .map((article) => ({
            title: article.title,
            description: article.summary,
            link: article.url,
            pubDate: parseDate(article.publish_time, 'X'),
            author: article.source_name,
            image: article.image,

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented ids: 1, 2, or 3 — see the route description table
  2. If jiemian added a new account type, add it to categoryMap in lib/routes/jiemian/account.ts:10-14 with its ckey
  3. Confirm the request path matches /jiemian/account/main/:id exactly

Example fix

// before
const category = categoryMap[id];
if (!category) {
    throw new InvalidParameterError('Invalid id');
}
// after — surface the valid options
const category = categoryMap[id];
if (!category) {
    throw new InvalidParameterError(`Invalid id '${id}'. Valid ids: ${Object.keys(categoryMap).join(', ')}`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

const VALID_IDS = new Set(['1', '2', '3']);
function isValidJiemianId(id: string | undefined): id is '1' | '2' | '3' {
  return id !== undefined && VALID_IDS.has(id);
}
// before calling the handler's ofetch:
if (!isValidJiemianId(ctx.req.param('id'))) {
  return ctx.json({ error: 'id must be 1, 2, or 3' }, 400);
}

Type guard

type JiemianId = '1' | '2' | '3';
function isJiemianId(id: unknown): id is JiemianId {
  return typeof id === 'string' && ['1', '2', '3'].includes(id);
}

Try / catch

try {
  return await handler(ctx);
} catch (e) {
  if (e instanceof InvalidParameterError) {
    return ctx.json({ error: e.message, validIds: ['1', '2', '3'] }, 400);
  }
  throw e;
}

Prevention

When it happens

Trigger: Request to /jiemian/account/main/4 (or 0, abc, etc.) — any id not in {'1','2','3'}. Also when the route is invoked without an id segment in some misconfigured reverse proxy.

Common situations: User guesses a category number; upstream adds a new account type that isn't reflected in categoryMap yet; trailing slash or URL encoding mangles the id.

Related errors


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