{"record":{"id":"719e783a6610597c","repo":"jackwener/OpenCLI","slug":"taobao-cart-requires-a-logged-in-taobao-session","errorCode":null,"errorMessage":"taobao cart requires a logged-in Taobao session","messagePattern":"taobao cart requires a logged-in Taobao session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/taobao/cart.js","lineNumber":92,"sourceCode":"            if (prev && prev.length > 2 && prev.length < 30 && !prev.match(/^(删除|\\\\d|￥|¥|券|退|满|超)/)) {\n              shop = prev;\n            }\n          }\n\n          results.push({\n            index: results.length + 1,\n            title: title.slice(0, 80),\n            price,\n            spec,\n            shop,\n          });\n          if (results.length >= ${limit}) break;\n        }\n        return { results };\n      })()\n    `);\n        if (data?.error === 'auth-required') {\n            throw new AuthRequiredError('taobao cart requires a logged-in Taobao session');\n        }\n        return Array.isArray(data?.results) ? data.results : [];\n    },\n});\n","sourceCodeStart":74,"sourceCodeEnd":97,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/taobao/cart.js#L74-L97","documentation":"The taobao cart command's page-side script signals { error: 'auth-required' } when Taobao returns a not-logged-in/cart-empty-guest response; the Node wrapper converts that into AuthRequiredError. It means cart scraping needs an authenticated Taobao session and the current browser has none.","triggerScenarios":"Calling the taobao cart command (fetching cart items via in-page evaluate) when the page's data indicates a guest session — Taobao redirects or embeds an auth-required marker instead of cart contents.","commonSituations":"Cart queried before login; session expired mid-session; cookies restored incompletely (missing cookie2/tracknick); anti-bot interstitial replacing the cart page.","solutions":["Run the taobao auth/login flow first, then retry the cart command","Restore a valid saved cookie/storage state before invoking cart","Catch AuthRequiredError and route to interactive login automatically","Verify session with verifyTaobaoIdentity before scraping cart"],"exampleFix":"// before\nconst items = await taobaoCart(page, { limit });\n// after\ntry {\n  const items = await taobaoCart(page, { limit });\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await taobaoLogin(page);\n    return taobaoCart(page, { limit });\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!(await hasTaobaoSessionCookie(page))) {\n  throw new Error('Login to Taobao before fetching cart');\n}","typeGuard":"function isAuthRequiredError(e) {\n  return e instanceof AuthRequiredError || /logged-in Taobao session/.test(String(e?.message));\n}","tryCatchPattern":"try {\n  const cart = await taobaoCart(page, { limit });\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await taobaoLogin(page);\n    return taobaoCart(page, { limit });\n  }\n  throw e;\n}","preventionTips":["Always verify identity (verifyTaobaoIdentity) before cart operations","Persist and restore a valid session before batch cart jobs","Catch AuthRequiredError centrally and funnel to the login flow","Refresh sessions proactively; Taobao sessions expire"],"tags":["auth","taobao","cart","scraping"],"backgroundTag":"auth-required-for-scrape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}