DIYgod/RSSHub · error · TypeError
No posts found for the given IDs
Error message
No posts found for the given IDs
What it means
Thrown by `getPosts` in chikubi/utils.ts when the WordPress REST API (`/wp-json/wp/v2/posts`) response is not an array. Unusually uses `TypeError` rather than `Error`. WP REST normally returns an array of post objects; a non-array body means WP returned an error object (e.g. `{ code: 'rest_no_route', message: '...' }`) or a 404 HTML page.
Source
Thrown at lib/routes/chikubi/utils.ts:87
const $ = load(description);
return $('body')
.children()
.toArray()
.map((el) => $.html(el))
.join('');
}
const WP_REST_API_URL = 'https://chikubi.jp/wp-json/wp/v2';
export async function getPosts(ids?: string[]): Promise<DataItem[]> {
const url = `${WP_REST_API_URL}/posts${ids?.length ? `?include=${ids.join(',')}` : ''}`;
const cachedData = await cache.tryGet(url, async () => {
const response = await got(url);
const data = JSON.parse(response.body);
if (!Array.isArray(data)) {
throw new TypeError('No posts found for the given IDs');
}
return data.map(({ title, link, date, content }) => ({
title: title.rendered,
link,
pubDate: parseDate(date),
description: processDescription(content.rendered),
}));
});
return ((Array.isArray(cachedData) ? cachedData : []) as Array<DataItem | null>).filter((item): item is DataItem => item !== null);
}
const API_TYPES = {
tag: 'tags',
category: 'categories',
};
View on GitHub (pinned to bed535e087)
Solutions
- Call `https://chikubi.jp/wp-json/wp/v2/posts?include=<ids>` directly in a browser to see the real body.
- If the body is an error object, surface `data.message` instead of a generic 'No posts found'.
- Drop or correct invalid ids in the `include` list.
- Maintainers: consider checking `response.statusCode` and parsing only when 200.
Example fix
// before
if (!Array.isArray(data)) {
throw new TypeError('No posts found for the given IDs');
}
// after
if (!Array.isArray(data)) {
throw new Error(`WordPress REST error: ${data?.message ?? 'response was not an array'}`);
} Defensive patterns
Strategy: validation
Validate before calling
const resp = await got(url);
const data = JSON.parse(resp.body);
if (!Array.isArray(data)) {
// surface WP error message instead of a generic throw
throw new Error(`WP REST: ${data?.message ?? 'non-array response'} (status ${resp.statusCode})`);
} Type guard
function isPostArray(r: unknown): r is Array<{ id: number; title: { rendered: string }; link: string; date: string; content: { rendered: string } }> {
return Array.isArray(r);
} Prevention
- Check `resp.statusCode === 200` before parsing; a 404 HTML page parses to a non-array.
- Confirm the WP REST API is not disabled by a security plugin on the source site.
- Validate every id in the `include` list exists before batching.
When it happens
Trigger: One or more of the `include` ids do not exist and WP returns an error envelope instead of an array; the `posts` endpoint is disabled by a security plugin; `got` receives a 404 HTML page and `JSON.parse` still yields an object (not throwing); rate-limiting returns `{ code: 'rest_disabled' }`.
Common situations: Passing stale/cached ids that have been deleted, REST API hidden by a hardening plugin (e.g. Wordfence, iThemes Security), or a transient maintenance-page HTML response.
Related errors
- Failed to fetch channel data from Castbox
- Failed to fetch episode list from Castbox
- API error: ${response.message}
- API error: ${response.message}
- No ${type} found for slug: ${slug}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/a60ac795d9a200eb.
Report an issue: GitHub.