DIYgod/RSSHub · warning · Error
无效的排序类型
Error message
无效的排序类型
What it means
Thrown by the asianfanfics tag route when the URL :type parameter is missing or not one of the allowed sort codes L, N, O, C, OS (each mapped to a Chinese label). It is an input-validation guard before the ofetch to asianfanfics.com, so the request never fires for an invalid sort type.
Source
Thrown at lib/routes/asianfanfics/tag.ts:51
handler,
};
type Type = 'L' | 'N' | 'O' | 'C' | 'OS';
const typeToText = {
L: '最近更新',
N: '最近发布',
O: '最早发布',
C: '已完成',
OS: '短篇',
};
async function handler(ctx) {
const tag = ctx.req.param('tag');
const type = ctx.req.param('type') as Type;
if (!type || !['L', 'N', 'O', 'C', 'OS'].includes(type)) {
throw new Error('无效的排序类型');
}
const link = `https://www.asianfanfics.com/browse/tag/${tag}/${type}`;
const response = await ofetch(link, {
headers: {
'user-agent': config.trueUA,
Referer: 'https://www.asianfanfics.com/',
},
});
const $ = load(response);
const items: DataItem[] = $('.primary-container .excerpt')
.toArray()
.filter((element) => {
const $element = $(element);
return $element.find('.excerpt__title a').length > 0;
})
.map((element) => {View on GitHub (pinned to bed535e087)
Solutions
- Use one of the documented sort codes: L (recently updated), N (recently published), O (earliest published), C (completed), OS (short stories).
- If you believe a new code should be supported, add it to both the includes array and the labels map and open a PR.
Example fix
// before
if (!type || !['L', 'N', 'O', 'C', 'OS'].includes(type)) {
throw new Error('无效的排序类型');
}
// after: derive a typed constant so the allow-list and labels stay in sync
const SORT_LABELS = { L: '最近更新', N: '最近发布', O: '最早发布', C: '已完成', OS: '短篇' } as const;
type SortType = keyof typeof SORT_LABELS;
const VALID_SORTS = new Set(Object.keys(SORT_LABELS));
if (!VALID_SORTS.has(type)) {
throw new InvalidParameterError(`Invalid sort type: ${type}. Allowed: ${[...VALID_SORTS].join(', ')}`);
} Defensive patterns
Strategy: validation
Validate before calling
const VALID_SORTS = new Set(['L', 'N', 'O', 'C', 'OS']);
const type = String(ctx.req.param('type') ?? '').toUpperCase();
if (!VALID_SORTS.has(type)) {
throw new InvalidParameterError(`Invalid sort type. Allowed: ${[...VALID_SORTS].join(', ')}`);
} Type guard
const SORT_LABELS = { L: '最近更新', N: '最近发布', O: '最早发布', C: '已完成', OS: '短篇' } as const;
type SortType = keyof typeof SORT_LABELS;
function isSortType(v: string): v is SortType {
return Object.prototype.hasOwnProperty.call(SORT_LABELS, v);
} Prevention
- Derive the allow-list and labels from a single object so they cannot drift.
- Use InvalidParameterError (not generic Error) so RSSHub returns the correct status.
When it happens
Trigger: Calling /asianfanfics/tag/:tag/:type with a type value outside {L,N,O,C,OS}, or omitting type entirely so ctx.req.param('type') is undefined.
Common situations: User mistypes the sort code; route example copied with a wrong placeholder; upstream adds a new sort option that the route has not whitelisted.
Related errors
- 关键词不能为空
- Invalid language: ${language}. Allowed values are: ${[...val
- 暂不支持对${type}的订阅
- Unsupported server
- Tag not found
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/1eee58721888a502.
Report an issue: GitHub.