DIYgod/RSSHub · error · Error
Unknown type: ${item.type}
Error message
Unknown type: ${item.type} What it means
Thrown by the `parseContent` function in the Economist Global Business Review route when iterating over article body items from the Hummingbird API. The switch handles `paragraph`, `image`, and `subtitle` types. Any other `item.type` hits the default case and throws. This is a forward-compatibility guard: it surfaces schema changes from the upstream API rather than silently dropping content.
Source
Thrown at lib/routes/economist/global-business-review.ts:35
const DESCRIPTION = {
en: 'The Economist Global Business Review is a new bilingual digital app from the editors of The Economist Group.',
cn: '《经济学人·商论》是《经济学人》2015年5月推出的旗下中英双语APP,萃取《经济学人》在商业、金融、科技等领域的精华文章,为中国读者呈现全球视角的深度分析,并鼓励中国的读者批判性地思考中国和全球重大议题。',
tw: '《經濟學人·商論》是經濟學人集團官方中英雙語電子APP,萃取《經濟學人》在商業、金融、科技等領域的精華文章,為中國讀者呈現全球視角的深度分析,並鼓勵中國的讀者批判性地思考中國和全球的重大議題。',
};
const parseContent = function (item, article_id, language) {
switch (item.type) {
case 'paragraph':
return parseParagraph(item.data, language);
case 'image':
return parseImage(item.data, article_id, language);
case 'subtitle':
return parseParagraph(item.data, language, 'h3');
default:
throw new Error(`Unknown type: ${item.type}`);
}
};
const parseTitle = function (data, language) {
const content = Object.assign({}, ...data.map((x) => ({ [x.lang]: x.text })));
return language.map((item) => content[ALLOW_LANGUAGE[item]]).join('');
};
const parseParagraph = function (data, language, type = 'p') {
const content = Object.assign({}, ...data.map((x) => ({ [x.lang]: x.text })));
return `<div>${language.map((item) => `<${type}>${content[ALLOW_LANGUAGE[item]]}</${type}>`).join('')}</div>`;
};
const parseImage = function (data, article_id, language) {
const content = Object.assign({}, ...data.map((x) => ({ [x.lang]: x.image_path })));
return `<div><img src="https://businessreviewglobal-cdn.com/article_images/${article_id}/${encodeURIComponent(content[ALLOW_LANGUAGE[language[0]]])}"/></div>`;
};
View on GitHub (pinned to bed535e087)
Solutions
- Log the unknown `item.type` value to identify what new block the API introduced.
- Add a new case branch for the type if it carries meaningful content, or return an empty string to skip it gracefully.
- If the type is cosmetic (divider, spacer), return `''` instead of throwing so the rest of the article renders.
- Check the API response structure at `https://api.hummingbird.businessreview.global/api/article/index?id=<id>` for the full schema.
Example fix
// before
default:
throw new Error(`Unknown type: ${item.type}`);
// after — skip unknown types gracefully instead of failing the entire article
// Add a console.warn for visibility during development
default:
console.warn(`Unknown Economist content type: ${item.type}`);
return ''; Defensive patterns
Strategy: type-guard
Validate before calling
const KNOWN_CONTENT_TYPES = new Set(['paragraph', 'image', 'subtitle']);
function hasKnownType(item: { type: string }): boolean {
return KNOWN_CONTENT_TYPES.has(item.type);
} Type guard
type KnownContentType = 'paragraph' | 'image' | 'subtitle';
function isKnownContentType(item: { type: string }): item is { type: KnownContentType; data: any } {
return item.type === 'paragraph' || item.type === 'image' || item.type === 'subtitle';
} Try / catch
// Filter out unknown content types before mapping, or handle them gracefully
const html = data.content
.filter(isKnownContentType)
.map((item) => parseContent(item, article_id, language))
.join(''); Prevention
- Design content parsers to gracefully skip unknown types rather than throwing.
- Log unknown types to a monitoring channel so schema changes are detected early.
- Periodically check the upstream API schema for new content block types.
- Use a filter-then-map pattern to isolate parsing failures from unknown types.
When it happens
Trigger: The Economist/Hummingbird API adds a new content block type to the article body array (e.g., `video`, `quote`, `pull-quote`, `divider`, `tweet`). The route iterates `data.content.map((item) => parseContent(item, ...))` and the unhandled type reaches the default case.
Common situations: The Economist redesigns the Global Business Review app and introduces new content blocks. An article contains an embedded interactive element with a type the parser has never seen. The API version changes and old types are renamed.
Related errors
- Failed to fetch channel data from Castbox
- Failed to fetch episode list from Castbox
- No posts found for the given IDs
- No ${type} found for slug: ${slug}
- API error: ${response.message}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/a79f0dab10b2a223.
Report an issue: GitHub.