DIYgod/RSSHub · warning · Error

No articles found for category: ${category}

Error message

No articles found for category: ${category}

What it means

The The Block route fetches https://www.theblock.co/api/category/<category> and reads response.data?.articles (defaulting to []). If that array is empty after the fetch, it throws a generic Error claiming no articles were found. An empty result can mean either a wrong category or a shape change in the category API.

Source

Thrown at lib/routes/theblock/index.ts:47

        },
    ],
    description: 'Get latest news from TheBlock by category. Note that due to website limitations, only article summaries may be available.',
};

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

    const apiUrl = `https://www.theblock.co/api/category/${category}`;

    try {
        const response = await ofetch(apiUrl);

        // Extract articles from the nested data structure
        const articles = response.data?.articles || [];

        if (!articles.length) {
            throw new Error(`No articles found for category: ${category}`);
        }

        const items = await Promise.all(
            articles.slice(0, limit).map((article) =>
                cache.tryGet(`theblock:article:${article.url}`, async () => {
                    try {
                        // Try to get the full article
                        const articleResponse = await ofetch(`https://www.theblock.co/api/post/${article.id}/`);

                        const post = articleResponse.post;
                        const $ = load(post.body, null, false);

                        // If we successfully got the article content
                        if (post.body.length) {
                            // Remove unwanted elements
                            $('.copyright').remove();

                            let fullText = '';

View on GitHub (pinned to bed535e087)

Solutions

  1. Confirm the category slug exists on theblock.co and that the API actually returns articles for it (open the API URL directly).
  2. Inspect the full response to see whether articles moved to a different key (e.g. response.data.posts) and update the read path.
  3. Distinguish 'unknown category' (likely 4xx/error envelope) from 'known but empty category' and only throw for the former, since RSSHub has an allowEmpty mechanism.
  4. Replace the generic Error with a more specific message that includes the API URL and response shape for diagnosis.

Example fix

// before
const articles = response.data?.articles || [];
if (!articles.length) {
    throw new Error(`No articles found for category: ${category}`);
}

// after: tolerate shape drift and use a precise error
const articles = response.data?.articles ?? response.articles ?? [];
if (!articles.length) {
    throw new Error(`No articles for category "${category}" (apiUrl=${apiUrl}). Response keys: ${Object.keys(response).join(',')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

function hasArticles(r: unknown): boolean {
    const data = (r as { data?: { articles?: unknown[] } })?.data;
    return Array.isArray(data?.articles) && data.articles.length > 0;
}
// before relying on the category feed, verify hasArticles(response)

Type guard

function isTheBlockCategoryResponse(r: unknown): r is { data: { articles: unknown[] } } {
    return typeof r === 'object' && r !== null && Array.isArray((r as { data?: { articles?: unknown[] } }).data?.articles);
}

Try / catch

try {
    return await handler(ctx);
} catch (e) {
    if (e instanceof Error && /No articles found for category/.test(e.message)) {
        // treat unknown category as 404, known-but-empty as an empty feed
        return emptyFeed();
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling the category API with a category whose data.articles is missing or empty: unknown category slug, an API version that nests articles elsewhere, or the category genuinely has no published articles.

Common situations: User passes a category slug the API does not recognize; The Block renames the articles field or wraps data differently; a temporary empty response during site maintenance.

Related errors


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