DIYgod/RSSHub · error · Error

没有获取到数据

Error message

没有获取到数据

What it means

Thrown when the Eleduck (电鸭社区) posts API at `svc.eleduck.com/api/v1/posts` returns a response whose `data` object does not contain a `posts` field. The check `posts === undefined` catches cases where the API returned an error object, empty body, or changed its response shape. The Chinese message means 'No data retrieved'.

Solutions

  1. Verify the category id is valid by checking the route description table or visiting `https://eleduck.com/categories/<id>`.
  2. If the id is valid, the Eleduck API may be temporarily unavailable — retry after a few minutes.
  3. Log `response.data` to inspect the full API response and determine if the schema changed.
  4. If the API endpoint moved, update the URL in the got() call.
Defensive patterns

Strategy: validation

Validate before calling

const VALID_CATEGORY_IDS = new Set(['0','1','2','3','4','5','10','12','14','15','17','19','21','22','23','24']);

function validateCategoryId(cid: string | undefined): string {
    const resolved = cid ?? '0';
    if (!VALID_CATEGORY_IDS.has(resolved)) {
        throw new InvalidParameterError(`Invalid category id: ${cid}`);
    }
    return resolved;
}

Type guard

function isDefinedPosts(response: unknown): response is { posts: unknown[] } {
    return typeof response === 'object' && response !== null &&
        Array.isArray((response as any).posts);
}

Prevention

When it happens

Trigger: A user passes a category `id` that does not exist on Eleduck (e.g., `/eleduck/posts/999`). The API returns a top-level error object without a `posts` array. Alternatively, the Eleduck API is temporarily down or changed its response format.

Common situations: User passes a category id not listed in the route description table (valid ids: 0–5, 10, 12, 14, 15, 17, 19, 21–24). The Eleduck service undergoes maintenance. A network proxy or CDN returns an HTML error page that ofetch/got parses as an object without a posts field.

Related errors


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

Appendix: source

Thrown at lib/routes/eleduck/posts.ts:62

| 12 | 英语     |
| 14 | 电鸭官方 |
| 15 | 独立产品 |
| 17 | 闲话开源 |
| 19 | Web3     |
| 21 | 设计     |
| 22 | 人才库   |
| 23 | Upwork   |
| 24 | 经验课   |`,
};

async function handler(ctx) {
    const cid = ctx.req.param('id') || 0;

    const response = await got(`https://svc.eleduck.com/api/v1/posts?category=${cid}&sort=-published_at&page=1`);

    const { posts } = response.data;
    if (posts === undefined) {
        throw new Error('没有获取到数据');
    }

    const cname = await getCateName(cid);

    return {
        title: `电鸭社区的文章--${cname}`,
        link: `https://eleduck.com/categories/${cid}`,
        description: `电鸭社区的文章,栏目为${cname}`,
        item: posts.map((item) => ({
            title: item.title,
            description: item.summary,
            pubDate: item.published_at,
            link: `https://eleduck.com/${item.category.id === 22 ? 'tposts' : 'posts'}/${item.id}`,
            author: item.user.nickname,
        })),
    };
}

View on GitHub (pinned to bed535e087)