DIYgod/RSSHub · error · Error
Category "${categorySlug}" not found
Error message
Category "${categorySlug}" not found What it means
Thrown when the Secret San Francisco WordPress categories API returns an empty array for the requested category slug. The route looks up the numeric category id via /wp-json/wp/v2/categories?slug={categorySlug}; an empty response means no WordPress category matches that slug.
Source
Thrown at lib/routes/secretsanfrancisco/rss.tsx:49
handler,
};
async function handler(ctx) {
const baseUrl = 'https://secretsanfrancisco.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
- Confirm the slug exists: open {baseUrl}/wp-json/wp/v2/categories and find the matching slug.
- Correct the route URL to use the exact, lowercase WordPress slug.
- Flush the cache key for the categories endpoint so a corrected slug is re-resolved immediately.
- If the category was renamed, update the route example / any radar mappings.
Example fix
// before
if (!data || data.length === 0) {
throw new Error(`Category "${categorySlug}" not found`);
}
// after — same throw, but invalidate the cached lookup so a corrected slug works next time
if (!data || data.length === 0) {
await cache.del(`${baseUrl}${categoryApiPath}`);
throw new Error(`Category "${categorySlug}" not found on ${baseUrl}`);
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate the slug shape (lowercase, no spaces) and probe the WP API.
function isValidSlug(slug: string): boolean {
return /^[a-z0-9-]+$/.test(slug);
}
if (categorySlug && !isValidSlug(categorySlug)) {
throw new InvalidParameterError(`Invalid category slug: ${categorySlug}`);
} Type guard
const isWpCategory = (o: any): o is { id: number; name: string; link: string } =>
o !== null && typeof o === 'object' && typeof o.id === 'number'; Try / catch
try {
category = await cache.tryGet(`${baseUrl}${categoryApiPath}`, lookup);
} catch (e) {
if (e instanceof Error && /not found/.test(e.message)) {
return ctx.json({ error: `Category '${categorySlug}' does not exist on ${baseUrl}.` }, 404);
}
throw e;
} Prevention
- Validate the slug format before the API call to catch obvious typos.
- Invalidate the cached categories lookup on a 'not found' so a corrected slug resolves immediately.
- Expose the list of valid slugs (via /wp-json/wp/v2/categories) in route documentation.
When it happens
Trigger: GET {baseUrl}/wp-json/wp/v2/categories?slug={categorySlug} returns [] (data.length === 0). The category slug supplied in the route path does not match any term slug in the site's WordPress taxonomy.
Common situations: The subscriber mistyped the category slug; the category was renamed/removed on the WordPress site; trailing/leading characters or case mismatch (slugs are case-sensitive); a cached negative result under the cache key blocks re-resolution until expiry.
Related errors
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/0253012e2a997430.
Report an issue: GitHub.