{"record":{"id":"7140069da9430ec3","repo":"jackwener/OpenCLI","slug":"xianyu-search-request-failed-result-error","errorCode":null,"errorMessage":"Xianyu search request failed: ${result.error}","messagePattern":"Xianyu search request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/search.js","lineNumber":242,"sourceCode":"        if (result?.error === 'auth-required') {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');\n        }\n        if (result?.error === 'blocked') {\n            throw new CommandExecutionError('Xianyu returned a verification page or blocked the current browser session');\n        }\n        if (result?.error === 'mtop-not-ready') {\n            throw selectorError('window.lib.mtop', '闲鱼页面未完成初始化，无法调用搜索接口');\n        }\n        if (!result || typeof result !== 'object') {\n            throw new CommandExecutionError('Xianyu search returned a malformed response');\n        }\n        const errorCode = String(result?.error_code || '');\n        const errorMessage = String(result?.error_message || '');\n        if (/FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED|FAIL_SYS_TOKEN/.test(errorCode) || /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED/.test(errorMessage)) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');\n        }\n        if (result?.error) {\n            throw new CommandExecutionError(errorMessage || `Xianyu search request failed: ${result.error}`);\n        }\n        if (!Array.isArray(result.items)) {\n            throw new CommandExecutionError('Xianyu search response did not include an items array');\n        }\n        const items = result.items;\n        if (!items.length) {\n            throw new EmptyResultError('xianyu search', '没有匹配的商品（筛选条件可能过窄，或当前关键词无结果）');\n        }\n        return items.map((item, index) => ({ rank: index + 1, ...item }));\n    },\n});\nexport const __test__ = {\n    ROWS_PER_PAGE,\n    MAX_LIMIT,\n    normalizeLimit,\n    buildSearchUrl,\n    parsePriceArg,\n    buildSearchFilter,","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/search.js#L224-L260","documentation":"If the mtop response contains an error not classified as session-expiry, blocked, or mtop-not-ready, the CLI surfaces it as a CommandExecutionError. The message prefers the server's error_message and falls back to 'Xianyu search request failed: <result.error>'.","triggerScenarios":"result.error is truthy with an unrecognized code — e.g. mtop system errors (FAIL_SYS_* not session-related), API param errors, or server-side business errors returned by the search API.","commonSituations":"Xianyu API changes introducing new error codes, transient server-side failures (FAIL_SYS_FLOW / gateway errors), unusual query strings rejected by the API.","solutions":["Read the surfaced error_message to identify the server-reported cause","Retry after a short delay for transient FAIL_SYS_* gateway errors","Simplify the query/filters (remove province/city or price bounds) to rule out param issues","Update the library if the error persists (API surface may have changed)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await xianyuSearch(args); } catch (e) { if (e instanceof CommandExecutionError && /request failed/.test(e.message)) { console.error(e.message); await backoff(); return xianyuSearch(simplifiedArgs); } throw e; }","preventionTips":["Log the surfaced error_message for diagnosis before retrying","Retry transient FAIL_SYS_* errors with backoff","Reduce filters/query complexity when a persistent server error appears","Keep the library updated for new Xianyu error codes"],"tags":["api-error","mtop","xianyu"],"backgroundTag":"upstream-api-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}