{"record":{"id":"a62d6f3930c484dd","repo":"DIYgod/RSSHub","slug":"type-slug-not-found-a62d6f","errorCode":null,"errorMessage":"${type} ${slug} not found","messagePattern":"(.+?) (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/landiannews/utils.ts","lineNumber":18,"sourceCode":"import sanitizeHtml from 'sanitize-html';\n\nimport cache from '@/utils/cache';\nimport ofetch from '@/utils/ofetch';\nimport { parseDate } from '@/utils/parse-date';\n\nconst rootUrl = 'https://www.landiannews.com/';\n\nconst getRenderedText = (html: string) => sanitizeHtml(html, { allowedTags: [], allowedAttributes: {} });\n\nconst getPubDate = (dateGmt?: string, date?: string) => (dateGmt ? parseDate(`${dateGmt}Z`) : date ? parseDate(date) : undefined);\n\nconst fetchTaxonomy = async (slug: string, type: 'categories' | 'tags') => {\n    const taxonomyUrl = `${rootUrl}wp-json/wp/v2/${type}?slug=${slug}`;\n    const cachedTaxonomy = await cache.tryGet(taxonomyUrl, async () => {\n        const taxonomyData = await ofetch(taxonomyUrl);\n        if (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) {\n            throw new Error(`${type} ${slug} not found`);\n        }\n        return { id: taxonomyData[0].id, name: taxonomyData[0].name };\n    });\n    return cachedTaxonomy;\n};\n\nconst fetchCategory = async (categorySlug: string) => await fetchTaxonomy(categorySlug, 'categories');\nconst fetchTag = async (tagSlug: string) => await fetchTaxonomy(tagSlug, 'tags');\n\nasync function fetchNewsItems(apiUrl: string) {\n    const data = await ofetch(apiUrl);\n\n    return data.map((item) => ({\n        title: getRenderedText(item.title.rendered),\n        description: item.content.rendered,\n        link: item.link,\n        pubDate: getPubDate(item.date_gmt, item.date),\n        author: item._embedded.author[0].name,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/landiannews/utils.ts#L1-L36","documentation":"Thrown by landiannews (蓝点网) fetchTaxonomy when the WordPress REST API at /wp-json/wp/v2/<categories|tags>?slug=<slug> returns an array whose first element lacks id/name (or the array is empty). The handler needs the taxonomy id to build the posts query, so a missing taxonomy is fatal. The error embeds both the type (categories|tags) and the slug for context.","triggerScenarios":"GET https://www.landiannews.com/wp-json/wp/v2/categories?slug=<x> (or .../tags?slug=<x>) returns [] or [{...without id/name...}]. Happens when the slug does not exist on the site, was renamed, or the REST API is disabled/errored. Note the result is cached via cache.tryGet, so a stale failure can persist.","commonSituations":"Typo in category/tag slug; slug renamed by 蓝点网; WP REST API blocked by a security plugin returning empty; cached empty result masking a now-valid slug.","solutions":["Confirm the slug exists by browsing https://www.landiannews.com/?cat=<x> or the tag page and copying the exact slug","If the REST API returns empty for valid slugs, the site may have disabled it — switch to HTML scraping","Bust the cached taxonomyUrl key (cache.tryGet caches the throw path too in some impls) so a transient empty isn't sticky","Handle the empty-array case distinctly from the missing-fields case for better diagnostics"],"exampleFix":"// before\nconst taxonomyData = await ofetch(taxonomyUrl);\nif (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) {\n    throw new Error(`${type} ${slug} not found`);\n}\n// after\nconst taxonomyData = await ofetch(taxonomyUrl);\nif (!Array.isArray(taxonomyData) || !taxonomyData[0]?.id || !taxonomyData[0]?.name) {\n    throw new Error(`${type} '${slug}' not found at ${taxonomyUrl} (got ${JSON.stringify(taxonomyData).slice(0, 120)})`);\n}","handlingStrategy":"validation","validationCode":"async function taxonomyExists(type: 'categories' | 'tags', slug: string): Promise<boolean> {\n  const data = await ofetch(`https://www.landiannews.com/wp-json/wp/v2/${type}?slug=${slug}`);\n  return Array.isArray(data) && !!data[0]?.id && !!data[0]?.name;\n}\nif (!(await taxonomyExists('categories', slug))) {\n  return ctx.json({ error: `category '${slug}' not found` }, 404);\n}","typeGuard":"interface WpTaxonomy { id: number; name: string }\nfunction isWpTaxonomyArray(v: unknown): v is WpTaxonomy[] {\n  return Array.isArray(v) && v.length > 0 && typeof v[0]?.id === 'number' && typeof v[0]?.name === 'string';\n}","tryCatchPattern":"try { return await handler(ctx); }\ncatch (e) {\n  if (e instanceof Error && /not found/.test(e.message)) {\n    // could be a stale cached empty result — bust and retry once\n    return ctx.json({ error: e.message }, 404);\n  }\n  throw e;\n}","preventionTips":["Verify slugs against the live WP REST API before subscribing","Short-TTL the taxonomy cache so renamed slugs self-heal","Fall back to HTML scraping if the REST API is disabled","Distinguish empty-array (slug missing) from missing-fields (API schema change)"],"tags":["api-response","validation","wordpress","cache-staleness"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}