DIYgod/RSSHub · error · Error
Invalid tagId
Error message
Invalid tagId
What it means
The FoodTalks API endpoint /basic/tag/{tagId} is expected to return a response object whose data field contains the tag metadata. When data is falsy (null or undefined), the tag does not exist in the system, so the route throws 'Invalid tagId' before attempting to fetch articles. This is a precondition check that fails fast rather than emitting an empty or broken feed.
Source
Thrown at lib/routes/foodtalks/tag.ts:32
radar: [
{
source: ['www.foodtalks.cn/news/tag/:tagId'],
},
],
name: '标签',
maintainers: ['TonyRL'],
handler,
url: 'www.foodtalks.cn',
};
const getTagName = async (tagId: string) => {
const response = await ofetch(`${apiBaseUrl}/basic/tag/${tagId}?language=ZH`, {
headers: {
referer: `${baseUrl}/`,
},
});
if (!response.data) {
throw new Error('Invalid tagId');
}
return response.data.name;
};
async function handler(ctx) {
const { tagId } = ctx.req.param();
const limit = Number(ctx.req.query('limit')) || 15;
const response = await ofetch(`${apiBaseUrl}/news/news/page`, {
headers: {
referer: `${baseUrl}/`,
},
query: {
current: 1,
size: limit,
tagId,
language: 'ZH',
},View on GitHub (pinned to bed535e087)
Solutions
- Confirm the tagId by opening the FoodTalks website and copying the numeric ID from the tag page URL or the API response.
- URL-encode or trim the tagId to remove accidental whitespace or path separators before the lookup.
- If the tag may be locale-specific, verify it exists for language=ZH (the hardcoded query) or extend the route to accept a language parameter.
- Fall back to the source website's tag page directly to confirm the tag is still active.
Example fix
// before
const response = await ofetch(`${apiBaseUrl}/basic/tag/${tagId}?language=ZH`, { headers: { referer: `${baseUrl}/` } });
if (!response.data) {
throw new Error('Invalid tagId');
}
// after
const trimmedId = tagId.trim();
const response = await ofetch(`${apiBaseUrl}/basic/tag/${encodeURIComponent(trimmedId)}?language=ZH`, { headers: { referer: `${baseUrl}/` } });
if (!response.data) {
throw new InvalidParameterError(`Tag "${trimmedId}" does not exist on FoodTalks`);
} Defensive patterns
Strategy: validation
Validate before calling
const trimmed = tagId.trim();
if (!trimmed) throw new InvalidParameterError('tagId is required'); Type guard
const isNonEmptyId = (v: string | undefined): v is string => !!v && v.trim().length > 0;
Prevention
- Trim and URL-encode tagId before the API call.
- Document where to find the numeric tag ID on the FoodTalks site.
- Consider accepting a language parameter instead of hardcoding ZH.
When it happens
Trigger: Calling the route with a tagId that is not registered in FoodTalks, a tagId copied from an old URL that was since deleted, or a tagId with trailing characters/whitespace that does not match any record. The API returns a 200 with an empty/null data payload rather than a 404.
Common situations: Users pasting a tag slug or name instead of the numeric tagId; tags being retired on the FoodTalks site; locale mismatches (the request hardcodes language=ZH) for tags that only exist in the EN locale.
Related errors
- response.error.message
- Invalid type parameter
- unknown site: ${site}
- Invalid type parameter
- Invalid category: ${category}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/788cbdbba6e10387.
Report an issue: GitHub.