DIYgod/RSSHub · error · Error

Category "${categorySlug}" not found

Error message

Category "${categorySlug}" not found

What it means

Thrown at lib/routes/thegadgetflow/rss.tsx:49 when the WordPress REST API endpoint `/wp-json/wp/v2/categories?slug={categorySlug}` returns an empty array, meaning no category on thegadgetflow.com matches the provided slug. The result is cached via cache.tryGet keyed on the full categories API URL. It uses a generic `Error` instead of `InvalidParameterError`.

Source

Thrown at lib/routes/thegadgetflow/rss.tsx:49

    handler,
};

async function handler(ctx) {
    const baseUrl = 'https://thegadgetflow.com';
    const categoryApiPath = '/wp-json/wp/v2/categories';
    const postApiPath = '/wp-json/wp/v2/posts';

    // get category number
    const categorySlug = ctx.req.param('category') || '';

    let category;
    if (categorySlug) {
        category = await cache.tryGet(`${baseUrl}${categoryApiPath}`, async () => {
            const { data } = await got(`${baseUrl}${categoryApiPath}`, {
                searchParams: { slug: categorySlug },
            });
            if (!data || data.length === 0) {
                throw new Error(`Category "${categorySlug}" not found`);
            }
            return data[0];
        });
    }

    const categoryId = category?.id;
    const categoryName = category?.name;
    const categoryLink = category?.link;

    // get posts
    const postsUrl = `${baseUrl}${postApiPath}`;
    const postsResponse = await got(postsUrl, {
        searchParams: {
            per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10,
            _embed: '',
            ...(categoryId && { categories: categoryId }),
        },
    });

View on GitHub (pinned to bed535e087)

Solutions

  1. Browse thegadgetflow.com, find the category page, and copy the exact slug from the URL (e.g. `/categories/cool-gadgets-gifts` → slug is `cool-gadgets-gifts`).
  2. Clear the cache key `https://thegadgetflow.com/wp-json/wp/v2/categories` if a previously-failing slug has since been created.
  3. If maintaining the route, replace `throw new Error(...)` with `throw new InvalidParameterError(...)` for proper HTTP 400 semantics.

Example fix

// before
if (!data || data.length === 0) {
    throw new Error(`Category "${categorySlug}" not found`);
}

// after
import InvalidParameterError from '@/errors/types/invalid-parameter';
// ...
if (!data || data.length === 0) {
    throw new InvalidParameterError(`Category "${categorySlug}" not found`);
}
Defensive patterns

Strategy: validation

Validate before calling

const response = await got(`https://thegadgetflow.com/wp-json/wp/v2/categories`, {
    searchParams: { slug: categorySlug },
});
if (!response.data || response.data.length === 0) {
    // slug is invalid; do not proceed to the route
    throw new Error(`Category slug "${categorySlug}" does not exist on thegadgetflow.com`);
}

Type guard

const isWpCategory = (d: unknown): d is { id: number; name: string; link: string } =>
    !!d && typeof d === 'object' && 'id' in d && 'name' in d;

Prevention

When it happens

Trigger: Requesting `/thegadgetflow/typo-slug`; the category was renamed or removed by the site admin; trailing slash or URL-encoded characters in the slug; the slug uses spaces or uppercase that WordPress normalized differently.

Common situations: User copies a category display name instead of the URL slug; old bookmarked RSS URL pointing to a deleted category; WordPress permalink structure change.

Related errors


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