{"record":{"id":"2cfbceeb26d6b8d2","repo":"jackwener/OpenCLI","slug":"errormessage-xianyu-item-detail-request-failed","errorCode":null,"errorMessage":"errorMessage || `Xianyu item detail request failed: ${result.error}`","messagePattern":"errorMessage \\|\\| `Xianyu item detail request failed: (.+?)`","errorType":"error_code","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/item.js","lineNumber":142,"sourceCode":"        if (result?.error === 'auth-required') {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu item detail requires a logged-in browser session');\n        }\n        if (result?.error === 'blocked') {\n            throw new EmptyResultError('xianyu item', 'Xianyu item detail is blocked by verification or risk control');\n        }\n        if (result?.error === 'mtop-not-ready') {\n            throw selectorError('window.lib.mtop', '闲鱼页面未完成初始化，无法调用商品详情接口');\n        }\n        if (!result || typeof result !== 'object') {\n            throw new EmptyResultError('xianyu item', '闲鱼商品详情接口未返回有效数据');\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/.test(errorCode) || /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED/.test(errorMessage)) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu item detail requires a logged-in browser session');\n        }\n        if (result.error) {\n            throw new EmptyResultError('xianyu item', errorMessage || `Xianyu item detail request failed: ${result.error}`);\n        }\n        if (!String(result.title || '').trim()) {\n            throw new EmptyResultError('xianyu item', 'No item detail was returned for the specified item_id');\n        }\n        return [result];\n    },\n});\nexport const __test__ = {\n    normalizeNumericId,\n    buildItemUrl,\n};\n","sourceCodeStart":124,"sourceCodeEnd":154,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/item.js#L124-L154","documentation":"clis/xianyu/item.js fetches a single Xianyu (Goofish) item detail via the browser automation session. When the API response contains an `error` field, the CLI throws an EmptyResultError whose message is the API's own error_message if present, otherwise a generic 'request failed' string. The library throws this because a response with an `error` field means the remote endpoint refused or failed the request, so no usable item payload exists.","triggerScenarios":"Calling the xianyu item detail command for an item_id where the Goofish API returns { error: ... } — e.g. API-side failure, throttling, or the mtop gateway returning a non-session business error that is not FAIL_SYS_SESSION_EXPIRED/SESSION_EXPIRED (those are routed to AuthRequiredError instead).","commonSituations":"Scraping deleted or region-blocked listings; Goofish API intermittently returning business errors under load; running with an incomplete session so the gateway returns a generic FAIL_SYS error not matched by the expired-session regex; stale or wrong item_id formats slipping through to the API.","solutions":["Re-run the command; transient API failures are the most common cause.","Verify the item_id is a valid current listing by opening the item URL in a normal browser.","Re-authenticate the browser session for www.goofish.com (the error is only shown when the error code was not a session-expiry code, but a fresh login often resolves generic FAIL_SYS errors too).","Check the error_message embedded in the thrown EmptyResultError — it mirrors the upstream API error and points at the real cause (rate limit, risk control, etc.).","Reduce request frequency / add delay between lookups if the upstream error indicates throttling or risk control."],"exampleFix":"// before: raw call fails with generic API error\nawait cli.run(['xianyu', 'item', '--item_id', itemId]);\n\n// after: validate input and handle empty result gracefully\nif (!/^\\d{6,}$/.test(itemId)) throw new Error('invalid item_id');\ntry {\n  await cli.run(['xianyu', 'item', '--item_id', itemId]);\n} catch (e) {\n  if (e instanceof EmptyResultError) console.warn('API rejected item lookup:', e.message);\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!/^\\d{6,}$/.test(String(itemId))) throw new Error(`invalid item_id: ${itemId}`);","typeGuard":"function isItemDetail(r) { return r != null && typeof r === 'object' && !('error' in r) && typeof r.title === 'string' && r.title.trim() !== ''; }","tryCatchPattern":"try {\n  const items = await itemDetail(itemId);\n} catch (e) {\n  if (e instanceof EmptyResultError) {\n    // e.message carries upstream error_message; log and retry/backoff\n    await sleep(RETRY_MS); return itemDetail(itemId);\n  }\n  if (e instanceof AuthRequiredError) return reauthenticate('www.goofish.com');\n  throw e;\n}","preventionTips":["Validate item_id format before calling.","Add backoff/retry for transient upstream API errors.","Keep the goofish.com session authenticated to avoid generic FAIL_SYS errors.","Log the embedded upstream error_message for diagnosis."],"tags":["xianyu","api-error","empty-result","scraping"],"backgroundTag":"upstream-api-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}