{"record":{"id":"da01cb4abd92c0bb","repo":"DIYgod/RSSHub","slug":"countresponse-data-errors-0-message","errorCode":null,"errorMessage":"countResponse.data.errors[0].message","messagePattern":"countResponse\\.data\\.errors\\[0\\]\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/lkong/thread.tsx","lineNumber":42,"sourceCode":"    maintainers: ['nczitzk', 'ma6254'],\n    handler,\n};\n\nasync function handler(ctx) {\n    const id = ctx.req.param('id');\n\n    const rootUrl = 'https://www.lkong.com';\n    const apiUrl = 'https://api.lkong.com/api';\n    const currentUrl = `${rootUrl}/thread/${id}`;\n\n    const countResponse = await got({\n        method: 'post',\n        url: apiUrl,\n        json: countReplies(id),\n    });\n\n    if (countResponse.data.errors) {\n        throw new Error(countResponse.data.errors[0].message);\n    }\n\n    const response = await got({\n        method: 'post',\n        url: apiUrl,\n        json: viewThread(id, Math.ceil(countResponse.data.data.thread.replies / 20)),\n    });\n\n    const items = response.data.data.posts.map((item) => ({\n        guid: item.pid,\n        author: item.user.name,\n        title: `#${item.lou} ${item.user.name}`,\n        link: `${rootUrl}/thread/${id}?pid=${item.pid}`,\n        pubDate: parseDate(item.dateline),\n        description:\n            (item.quote ? renderToString(<LkongQuote target={`${rootUrl}/thread/${id}?pid=${item.quote.pid}`} author={item.quote.author.name} content={renderContent(JSON.parse(item.quote.content))} />) : '') +\n            renderContent(JSON.parse(item.content)),\n    }));","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/lkong/thread.tsx#L24-L60","documentation":"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', '参数错误'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the thread ID by opening https://www.lkong.com/thread/{id} in a browser.","Inspect the actual errors[0].message text — it comes directly from lkong and will indicate the specific problem.","If the API changed its envelope, update the error-detection condition (e.g. check status code instead of an errors field).","Guard against errors[0] being undefined to avoid a secondary TypeError."],"exampleFix":"// before\nif (countResponse.data.errors) {\n    throw new Error(countResponse.data.errors[0].message);\n}\n\n// after — defensive access + context\nif (countResponse.data.errors?.length) {\n    throw new Error(`lkong API error for thread ${id}: ${countResponse.data.errors[0].message}`);\n}","handlingStrategy":"try-catch","validationCode":"const id = ctx.req.param('id');\nif (!/^\\d+$/.test(id)) {\n    throw new InvalidParameterError(`Thread id must be numeric, got '${id}'`);\n}","typeGuard":"function hasLkongErrors(d: unknown): d is { errors: Array<{ message: string }> } {\n    return typeof d === 'object' && d !== null && 'errors' in d && Array.isArray((d as any).errors) && (d as any).errors.length > 0;\n}","tryCatchPattern":"try {\n    const countResponse = await got({ method: 'post', url: apiUrl, json: countReplies(id) });\n    if (hasLkongErrors(countResponse.data)) {\n        throw new Error(`lkong thread ${id}: ${countResponse.data.errors[0]?.message ?? 'unknown API error'}`);\n    }\n} catch (e) {\n    throw new Error(`Failed to load lkong thread ${id}: ${(e as Error).message}`, { cause: e });\n}","preventionTips":["Validate the thread id is numeric before the API call.","Defensively access errors[0]?.message to avoid a secondary TypeError when the array is empty.","Surface the API's own error text — it indicates the specific problem (not found, permissions, etc.).","If the API envelope changes, update the error-detection predicate."],"tags":["api","external-error","dynamic-message","lkong","forum"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}