DIYgod/RSSHub · error · Error
Invalid data received from API
Error message
Invalid data received from API
What it means
Thrown as a plain Error when the Algolia multi-query search API response is malformed: either the top-level `data` is falsy, `data.results` is missing/not-an-array, or the results array has fewer than 2 entries. The handler sends two parallel queries (indexName 'User' and 'Request') and indexes into results[1] for works, so it requires at least 2 result entries. This guard prevents an out-of-bounds or undefined-property access downstream.
Source
Thrown at lib/routes/skeb/search.ts:62
body: {
requests: [
{
indexName: 'User',
query: keyword,
params: 'hitsPerPage=40',
filters: 'genres:art OR genres:comic OR genres:voice OR genres:novel OR genres:video OR genres:music OR genres:correction',
},
{
indexName: 'Request',
query: keyword,
params: 'hitsPerPage=40&filters=genre%3Aart%20OR%20genre%3Acomic%20OR%20genre%3Avoice%20OR%20genre%3Anovel%20OR%20genre%3Avideo%20OR%20genre%3Amusic%20OR%20genre%3Acorrection',
},
],
},
});
if (!data || !data.results || !Array.isArray(data.results) || data.results.length < 2) {
throw new Error('Invalid data received from API');
}
const works = data.results[1].hits;
if (!Array.isArray(works)) {
throw new TypeError('Invalid hits data received from API');
}
return works.map((item) => processWork(item)).filter(Boolean);
});
return {
title: `Skeb - Search Results for "${keyword}"`,
link: `${baseUrl}/search?q=${encodeURIComponent(keyword)}`,
item: items as DataItem[],
};
}
View on GitHub (pinned to bed535e087)
Solutions
- Inspect the raw Algolia response by replaying the POST to https://hb1jt3kre9-dsn.algolia.net/1/indexes/*/queries with the current headers to see the error body.
- If the API key was revoked, extract the new Algolia application-id and api-key from the Skeb website's network requests and update the hardcoded headers in search.ts.
- If Skeb changed their search provider, the route needs to be rewritten to use the new search endpoint.
- If this is transient (Algolia rate limit), retry after a short delay or reduce request frequency.
Defensive patterns
Strategy: type-guard
Validate before calling
if (!data || typeof data !== 'object') throw new Error('Invalid data from Algolia');
if (!('results' in data) || !Array.isArray(data.results) || data.results.length < 2) {
throw new Error('Algolia search returned insufficient results');
} Type guard
interface AlgoliaMultiQueryResponse {
results: Array<{ hits: unknown[] }>;
}
function isAlgoliaResponse(data: unknown): data is AlgoliaMultiQueryResponse {
return (
data !== null &&
typeof data === 'object' &&
'results' in data &&
Array.isArray((data as any).results) &&
(data as any).results.length >= 2
);
} Try / catch
try {
const data = await ofetch(url, { /* ... */ });
if (!isAlgoliaResponse(data)) throw new Error('Invalid data received from API');
const works = data.results[1].hits;
} catch (e) {
logger.error('Algolia search failed', e);
throw e;
} Prevention
- Do not hardcode third-party API keys; extract them dynamically from the source website if possible.
- Add response schema validation using a runtime type checker (e.g. zod) for complex API responses.
- Log the full Algolia error body when validation fails to aid debugging.
When it happens
Trigger: The Algolia endpoint returns an error object instead of the expected { results: [...] } shape; one of the two requested indexes ('User' or 'Request') was renamed or deleted by Skeb; or the hardcoded API key was revoked, causing Algolia to return an error JSON like { message: 'Invalid API Key' } that lacks a results array.
Common situations: Skeb rotated their Algolia API key (hardcoded as x-algolia-api-key in the source); Skeb migrated away from Algolia to a different search backend; or Algolia rate-limited the endpoint returning a throttled response.
Related errors
- Invalid hits data received from API
- Invalid data received from API
- Invalid data received from API
- 中国政府网搜索接口请求失败,错误代码:${response?.resultCode?.code ?? '未知'}
- Details not found for product ${item.product_id}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/5d146ed7cbd73e72.
Report an issue: GitHub.