{"record":{"id":"cb8fb2d91890eea5","repo":"jackwener/OpenCLI","slug":"dianping-com","errorCode":null,"errorMessage":"dianping.com","messagePattern":"dianping\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/dianping/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasDianpingSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.dianping.com' });\n  return cookies.some(c => c.name === 'dper' && c.value);\n}\n\nasync function verifyDianpingIdentity(page) {\n  if (!await hasDianpingSessionCookie(page)) {\n    throw new AuthRequiredError('dianping.com', 'Dianping dper cookie missing');\n  }\n  await page.goto('https://www.dianping.com/member/myinformation');\n  await page.wait(2);\n  const finalUrl = await page.evaluate(`location.href`);\n  if (/account\\.dianping\\.com\\/(pc)?login/.test(String(finalUrl || ''))) {\n    throw new AuthRequiredError('dianping.com', `Dianping member page redirected to login: ${finalUrl}`);\n  }\n  const info = await page.evaluate(`\n    (() => {\n      const nicknameEl = document.querySelector('.user-name, .username, .nickname, .user-info .name');\n      const nickname = (nicknameEl?.textContent || '').trim();\n      const profileLink = Array.from(document.querySelectorAll('a[href*=\"/member/\"]'))\n        .map(a => a.getAttribute('href') || '')\n        .find(h => /\\\\/member\\\\/\\\\d+/.test(h));\n      const uidMatch = String(profileLink || '').match(/\\\\/member\\\\/(\\\\d+)/);\n      return { user_id: uidMatch?.[1] || '', nickname };\n    })()\n  `);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/dianping/auth.js#L1-L29","documentation":"AuthRequiredError thrown by verifyDianpingIdentity when the browser context has no `dper` session cookie for www.dianping.com. Dianping requires this cookie to authenticate requests; without it any member page access will bounce to the login page. The library checks the cookie up-front to fail fast with a clear auth message.","triggerScenarios":"Calling any dianping command (search, verify, etc.) in a browser page where the user never logged in, or after cookies were cleared/expired so `page.getCookies({url:'https://www.dianping.com'})` contains no non-empty `dper` entry.","commonSituations":"Fresh automation profile with no saved cookies; cookies wiped between runs; logged into the wrong Dianping-related domain (m.dianping.com vs www.dianping.com); headless login flow failed silently.","solutions":["Run the dianping login flow (loginUrl https://account.dianping.com/pclogin) and complete it interactively to obtain the dper cookie.","Persist cookies between runs (save/restore browser storage state) so a prior login is reused.","Verify cookies are set for the www.dianping.com domain, not a sibling domain, and that the dper value is non-empty.","If dper exists but auth still fails, log in again — the cookie may be expired server-side."],"exampleFix":"// before\nawait cli.dianping.search({ keyword: '火锅' });\n// after\nif (!ctx.cookies.some(c => c.name === 'dper' && c.value)) {\n  await cli.dianping.login(); // completes account.dianping.com/pclogin\n}\nawait cli.dianping.search({ keyword: '火锅' });","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.dianping.com' });\nif (!cookies.some(c => c.name === 'dper' && c.value)) await runDianpingLogin(page);","typeGuard":"function hasDper(cookies) { return Array.isArray(cookies) && cookies.some(c => c.name === 'dper' && !!c.value); }","tryCatchPattern":"try { await cli.dianping.verify(); }\ncatch (e) { if (e.name === 'AuthRequiredError') { await cli.dianping.login(); return cli.dianping.verify(); } throw e; }","preventionTips":["Persist and reload browser storage state between runs so cookies survive.","Always log in on account.dianping.com/pclogin before data commands.","Check cookie domain is www.dianping.com and dper value is non-empty.","Re-login proactively when sessions are old."],"tags":["auth","cookies","dianping","login-required"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}