{"record":{"id":"8e092e4085ee7b5f","repo":"DIYgod/RSSHub","slug":"no-articles-found-for-category-category","errorCode":null,"errorMessage":"No articles found for category: ${category}","messagePattern":"No articles found for category: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"warning","filePath":"lib/routes/theblock/index.ts","lineNumber":47,"sourceCode":"        },\n    ],\n    description: 'Get latest news from TheBlock by category. Note that due to website limitations, only article summaries may be available.',\n};\n\nasync function handler(ctx): Promise<Data> {\n    const category = ctx.req.param('category');\n    const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10;\n\n    const apiUrl = `https://www.theblock.co/api/category/${category}`;\n\n    try {\n        const response = await ofetch(apiUrl);\n\n        // Extract articles from the nested data structure\n        const articles = response.data?.articles || [];\n\n        if (!articles.length) {\n            throw new Error(`No articles found for category: ${category}`);\n        }\n\n        const items = await Promise.all(\n            articles.slice(0, limit).map((article) =>\n                cache.tryGet(`theblock:article:${article.url}`, async () => {\n                    try {\n                        // Try to get the full article\n                        const articleResponse = await ofetch(`https://www.theblock.co/api/post/${article.id}/`);\n\n                        const post = articleResponse.post;\n                        const $ = load(post.body, null, false);\n\n                        // If we successfully got the article content\n                        if (post.body.length) {\n                            // Remove unwanted elements\n                            $('.copyright').remove();\n\n                            let fullText = '';","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/theblock/index.ts#L29-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the category slug exists on theblock.co and that the API actually returns articles for it (open the API URL directly).","Inspect the full response to see whether articles moved to a different key (e.g. response.data.posts) and update the read path.","Distinguish 'unknown category' (likely 4xx/error envelope) from 'known but empty category' and only throw for the former, since RSSHub has an allowEmpty mechanism.","Replace the generic Error with a more specific message that includes the API URL and response shape for diagnosis."],"exampleFix":"// before\nconst articles = response.data?.articles || [];\nif (!articles.length) {\n    throw new Error(`No articles found for category: ${category}`);\n}\n\n// after: tolerate shape drift and use a precise error\nconst articles = response.data?.articles ?? response.articles ?? [];\nif (!articles.length) {\n    throw new Error(`No articles for category \"${category}\" (apiUrl=${apiUrl}). Response keys: ${Object.keys(response).join(',')}`);\n}","handlingStrategy":"validation","validationCode":"function hasArticles(r: unknown): boolean {\n    const data = (r as { data?: { articles?: unknown[] } })?.data;\n    return Array.isArray(data?.articles) && data.articles.length > 0;\n}\n// before relying on the category feed, verify hasArticles(response)","typeGuard":"function isTheBlockCategoryResponse(r: unknown): r is { data: { articles: unknown[] } } {\n    return typeof r === 'object' && r !== null && Array.isArray((r as { data?: { articles?: unknown[] } }).data?.articles);\n}","tryCatchPattern":"try {\n    return await handler(ctx);\n} catch (e) {\n    if (e instanceof Error && /No articles found for category/.test(e.message)) {\n        // treat unknown category as 404, known-but-empty as an empty feed\n        return emptyFeed();\n    }\n    throw e;\n}","preventionTips":["Confirm the category slug exists on theblock.co and returns articles via the API.","Inspect the full response on empty results to catch envelope changes.","Differentiate 'unknown category' from 'known but empty' in the handler."],"tags":["api-contract","validation","parsing"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}