{"record":{"id":"c4c4f3048c00d3bb","repo":"DIYgod/RSSHub","slug":"json-stringify-collect","errorCode":null,"errorMessage":"${JSON.stringify(collect)}","messagePattern":"\\$\\{JSON\\.stringify\\(collect\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/xiaohongshu/user.ts","lineNumber":118,"sourceCode":"        notes.flatMap((n) =>\n            n.map(({ noteCard }) => {\n                const coverUrl = noteCard.cover.infoList.pop().url;\n                return {\n                    title: noteCard.displayTitle,\n                    link: coverUrl,\n                    guid: noteCard.displayTitle,\n                    description: `<img src=\"${coverUrl}\" width=\"${noteCard.cover.width}\" height=\"${noteCard.cover.height}\"><br>${noteCard.displayTitle}`,\n                    author: noteCard.user.nickname,\n                    upvotes: noteCard.interactInfo.likedCount,\n                };\n            })\n        );\n    const renderCollect = (collect) => {\n        if (!collect) {\n            throw new InvalidParameterError('该用户已设置收藏内容不可见');\n        }\n        if (collect.code !== 0) {\n            throw new Error(JSON.stringify(collect));\n        }\n        if (!collect.data.notes.length) {\n            throw new InvalidParameterError('该用户已设置收藏内容不可见');\n        }\n        return collect.data.notes.map((item) => ({\n            title: item.display_title,\n            link: `${url}/${item.note_id}`,\n            description: `<img src =\"${item.cover.info_list.pop().url}\"><br>${item.display_title}`,\n            author: item.user.nickname,\n            upvotes: item.interact_info.likedCount,\n        }));\n    };\n\n    return {\n        title,\n        description,\n        image,\n        link: url,","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/xiaohongshu/user.ts#L100-L136","documentation":"Generic Error thrown in renderCollect when collect is truthy but collect.code !== 0 — i.e. the collect API call succeeded at the transport level but Xiaohongshu returned a non-zero business code. The entire response is JSON.stringify'd into the message for diagnosis.","triggerScenarios":"The /api/sns/web/v2/note/collect/page XHR returned a body whose top-level code is non-zero (e.g. auth required, rate limited, parameter error) — user.ts:117-118.","commonSituations":"Xiaohongshu flagged the request (risk control without the full captcha page), the cookie/session is partial, or the user_id path is invalid.","solutions":["Read the JSON in the error message — the code and msg fields identify the exact business error.","Retry after a delay if it is risk-control related (often pairs with error 639 under heavier load).","Provide a valid XIAOHONGSHU_COOKIE (config.xiaohongshu.cookie) so the collect API authorizes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Inspect the API code before rendering\nif (collect && typeof collect === 'object' && 'code' in collect && collect.code !== 0) {\n    throw new Error(`xiaohongshu collect API code=${collect.code} msg=${collect.msg ?? ''}`);\n}","typeGuard":"function isXiaohongshuCollectApiError(e: unknown): boolean {\n    if (!(e instanceof Error)) return false;\n    try { JSON.parse(e.message); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n    return renderCollect(collect);\n} catch (e) {\n    if (isXiaohongshuCollectApiError(e)) {\n        const body = JSON.parse((e as Error).message);\n        if (body.code === <riskControlCode>) await backoffAndRetry();\n    }\n    throw e;\n}","preventionTips":["Provide a valid XIAOHONGSHU_COOKIE so the collect API does not return a business error.","Parse the JSON message to map known codes to user-facing guidance.","Rate-limit xiaohongshu requests to avoid risk-control codes."],"tags":["xiaohongshu","api","collect","authentication"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}