DIYgod/RSSHub · error · Error

${type} ${slug} not found

Error message

${type} ${slug} not found

What it means

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.

Source

Thrown at lib/routes/landiannews/utils.ts:18

import sanitizeHtml from 'sanitize-html';

import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

const rootUrl = 'https://www.landiannews.com/';

const getRenderedText = (html: string) => sanitizeHtml(html, { allowedTags: [], allowedAttributes: {} });

const getPubDate = (dateGmt?: string, date?: string) => (dateGmt ? parseDate(`${dateGmt}Z`) : date ? parseDate(date) : undefined);

const fetchTaxonomy = async (slug: string, type: 'categories' | 'tags') => {
    const taxonomyUrl = `${rootUrl}wp-json/wp/v2/${type}?slug=${slug}`;
    const cachedTaxonomy = await cache.tryGet(taxonomyUrl, async () => {
        const taxonomyData = await ofetch(taxonomyUrl);
        if (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) {
            throw new Error(`${type} ${slug} not found`);
        }
        return { id: taxonomyData[0].id, name: taxonomyData[0].name };
    });
    return cachedTaxonomy;
};

const fetchCategory = async (categorySlug: string) => await fetchTaxonomy(categorySlug, 'categories');
const fetchTag = async (tagSlug: string) => await fetchTaxonomy(tagSlug, 'tags');

async function fetchNewsItems(apiUrl: string) {
    const data = await ofetch(apiUrl);

    return data.map((item) => ({
        title: getRenderedText(item.title.rendered),
        description: item.content.rendered,
        link: item.link,
        pubDate: getPubDate(item.date_gmt, item.date),
        author: item._embedded.author[0].name,

View on GitHub (pinned to bed535e087)

Solutions

  1. Confirm the slug exists by browsing https://www.landiannews.com/?cat=<x> or the tag page and copying the exact slug
  2. If the REST API returns empty for valid slugs, the site may have disabled it — switch to HTML scraping
  3. Bust the cached taxonomyUrl key (cache.tryGet caches the throw path too in some impls) so a transient empty isn't sticky
  4. Handle the empty-array case distinctly from the missing-fields case for better diagnostics

Example fix

// before
const taxonomyData = await ofetch(taxonomyUrl);
if (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) {
    throw new Error(`${type} ${slug} not found`);
}
// after
const taxonomyData = await ofetch(taxonomyUrl);
if (!Array.isArray(taxonomyData) || !taxonomyData[0]?.id || !taxonomyData[0]?.name) {
    throw new Error(`${type} '${slug}' not found at ${taxonomyUrl} (got ${JSON.stringify(taxonomyData).slice(0, 120)})`);
}
Defensive patterns

Strategy: validation

Validate before calling

async function taxonomyExists(type: 'categories' | 'tags', slug: string): Promise<boolean> {
  const data = await ofetch(`https://www.landiannews.com/wp-json/wp/v2/${type}?slug=${slug}`);
  return Array.isArray(data) && !!data[0]?.id && !!data[0]?.name;
}
if (!(await taxonomyExists('categories', slug))) {
  return ctx.json({ error: `category '${slug}' not found` }, 404);
}

Type guard

interface WpTaxonomy { id: number; name: string }
function isWpTaxonomyArray(v: unknown): v is WpTaxonomy[] {
  return Array.isArray(v) && v.length > 0 && typeof v[0]?.id === 'number' && typeof v[0]?.name === 'string';
}

Try / catch

try { return await handler(ctx); }
catch (e) {
  if (e instanceof Error && /not found/.test(e.message)) {
    // could be a stale cached empty result — bust and retry once
    return ctx.json({ error: e.message }, 404);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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