DIYgod/RSSHub · error · Error

countResponse.data.errors[0].message

Error message

countResponse.data.errors[0].message

What it means

Thrown by the lkong (龙空) forum thread route when the countReplies API call returns a response containing an errors array. The route re-throws the API's own error message verbatim (countResponse.data.errors[0].message), so the actual text is dynamic and depends on what the lkong API reports — e.g. 'thread not found', 'permission denied', '参数错误'.

Source

Thrown at lib/routes/lkong/thread.tsx:42

    maintainers: ['nczitzk', 'ma6254'],
    handler,
};

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

    const rootUrl = 'https://www.lkong.com';
    const apiUrl = 'https://api.lkong.com/api';
    const currentUrl = `${rootUrl}/thread/${id}`;

    const countResponse = await got({
        method: 'post',
        url: apiUrl,
        json: countReplies(id),
    });

    if (countResponse.data.errors) {
        throw new Error(countResponse.data.errors[0].message);
    }

    const response = await got({
        method: 'post',
        url: apiUrl,
        json: viewThread(id, Math.ceil(countResponse.data.data.thread.replies / 20)),
    });

    const items = response.data.data.posts.map((item) => ({
        guid: item.pid,
        author: item.user.name,
        title: `#${item.lou} ${item.user.name}`,
        link: `${rootUrl}/thread/${id}?pid=${item.pid}`,
        pubDate: parseDate(item.dateline),
        description:
            (item.quote ? renderToString(<LkongQuote target={`${rootUrl}/thread/${id}?pid=${item.quote.pid}`} author={item.quote.author.name} content={renderContent(JSON.parse(item.quote.content))} />) : '') +
            renderContent(JSON.parse(item.content)),
    }));

View on GitHub (pinned to bed535e087)

Solutions

  1. Confirm the thread ID by opening https://www.lkong.com/thread/{id} in a browser.
  2. Inspect the actual errors[0].message text — it comes directly from lkong and will indicate the specific problem.
  3. If the API changed its envelope, update the error-detection condition (e.g. check status code instead of an errors field).
  4. Guard against errors[0] being undefined to avoid a secondary TypeError.

Example fix

// before
if (countResponse.data.errors) {
    throw new Error(countResponse.data.errors[0].message);
}

// after — defensive access + context
if (countResponse.data.errors?.length) {
    throw new Error(`lkong API error for thread ${id}: ${countResponse.data.errors[0].message}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const id = ctx.req.param('id');
if (!/^\d+$/.test(id)) {
    throw new InvalidParameterError(`Thread id must be numeric, got '${id}'`);
}

Type guard

function hasLkongErrors(d: unknown): d is { errors: Array<{ message: string }> } {
    return typeof d === 'object' && d !== null && 'errors' in d && Array.isArray((d as any).errors) && (d as any).errors.length > 0;
}

Try / catch

try {
    const countResponse = await got({ method: 'post', url: apiUrl, json: countReplies(id) });
    if (hasLkongErrors(countResponse.data)) {
        throw new Error(`lkong thread ${id}: ${countResponse.data.errors[0]?.message ?? 'unknown API error'}`);
    }
} catch (e) {
    throw new Error(`Failed to load lkong thread ${id}: ${(e as Error).message}`, { cause: e });
}

Prevention

When it happens

Trigger: Requesting /lkong/thread/:id with a nonexistent, deleted, or admin-only thread id. The lkong API returns an errors array for invalid auth, bad thread id, or server-side problems. Also possible if the API envelope changed and a legitimate response now contains an 'errors' field for warnings.

Common situations: Thread ID is mistyped or copied incompletely (lkong IDs are long numerics). The thread was deleted by moderators. The API requires authentication/cookies that the route does not provide. The API is under maintenance and returns a generic error.

Related errors


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