DIYgod/RSSHub · error · InvalidParameterError

Invalid time range: ${timeRange}

Error message

Invalid time range: ${timeRange}

What it means

Acfun article feed accepts five timeRange values (all, oneDay, threeDay, oneWeek, oneMonth) checked against a Set. Note timeRange is only meaningfully applied by upstream when sortType='hotScore'; for other sort types the handler forces 'all'.

Source

Thrown at lib/routes/acfun/article.ts:104

| 最新发表   | 最新动态        | 最热文章 |
| ---------- | --------------- | -------- |
| createTime | lastCommentTime | hotScore |

| 时间不限 | 24 小时 | 三天     | 一周    | 一个月   |
| -------- | ------- | -------- | ------- | -------- |
| all      | oneDay  | threeDay | oneWeek | oneMonth |`,
};

async function handler(ctx) {
    const { categoryId, sortType = 'createTime', timeRange = 'all' } = ctx.req.param();
    if (!Object.hasOwn(categoryMap, categoryId)) {
        throw new InvalidParameterError(`Invalid category Id: ${categoryId}`);
    }
    if (!sortTypeEnum.has(sortType)) {
        throw new InvalidParameterError(`Invalid sort type: ${sortType}`);
    }
    if (!timeRangeEnum.has(timeRange)) {
        throw new InvalidParameterError(`Invalid time range: ${timeRange}`);
    }

    const url = `${baseUrl}/v/list${categoryId}/index.htm`;
    const response = await got.post(
        `${baseUrl}/rest/pc-direct/article/feed?cursor=first_page&onlyOriginal=false&limit=10&sortType=${sortType}&timeRange=${sortType === 'hotScore' ? timeRange : 'all'}&${categoryMap[categoryId].realmId}`,
        {
            headers: {
                referer: url,
            },
        }
    );

    const list = response.data.data.map((item) => ({
        title: item.title,
        link: `${baseUrl}/a/ac${item.articleId}`,
        author: item.userName,
        pubDate: parseDate(item.createTime, 'x'),
        category: item.realmName,

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of: all, oneDay, threeDay, oneWeek, oneMonth (camelCase).
  2. Omit timeRange to accept the default 'all'.
  3. Remember timeRange only has effect when sortType='hotScore'.

Example fix

// before
/acfun/article/110/hotScore/one_week
// after
/acfun/article/110/hotScore/oneWeek
Defensive patterns

Strategy: validation

Validate before calling

const ACFUN_RANGE = new Set(['all','oneDay','threeDay','oneWeek','oneMonth']);
function validAcfunRange(r) {
  return ACFUN_RANGE.has(r);
}

Type guard

function isAcfunTimeRange(r): r is 'all'|'oneDay'|'threeDay'|'oneWeek'|'oneMonth' {
  return ['all','oneDay','threeDay','oneWeek','oneMonth'].includes(r);
}

Prevention

When it happens

Trigger: Calling /acfun/article/<id>/<sortType>/<timeRange> with timeRange not in {all, oneDay, threeDay, oneWeek, oneMonth} (case-sensitive).

Common situations: Passing a localized label ('一周'); typo ('oneweek'); snake_case instead of camelCase.

Related errors


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