{"record":{"id":"a0d7e2e30ab7a9cf","repo":"jackwener/OpenCLI","slug":"zhihu-search-request-failed-status-http-st","errorCode":null,"errorMessage":"Zhihu search request failed${status ? ` (HTTP ${status})` : ''}","messagePattern":"Zhihu search request failed(.+?)\\)` : ''\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/search.js","lineNumber":85,"sourceCode":"    return type;\n}\n\nfunction unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;\n    return payload;\n}\n\nfunction requireSearchPayload(data, url) {\n    const payload = unwrapEvaluateResult(data);\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('Zhihu search returned malformed payload');\n    }\n    if (payload.__httpError) {\n        const status = payload.__httpError;\n        if (status === 401 || status === 403) {\n            throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');\n        }\n        throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');\n    }\n    if (payload.__fetchError) {\n        throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));\n    }\n    if (!Array.isArray(payload.data)) {\n        throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);\n    }\n    if (!payload.paging || typeof payload.paging !== 'object') {\n        throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);\n    }\n    return payload;\n}\n\nfunction normalizeResultItem(item) {\n    if (!item || typeof item !== 'object' || item.type !== 'search_result' || !item.object || typeof item.object !== 'object') {\n        return null;\n    }\n    const obj = item.object;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/search.js#L67-L103","documentation":"requireSearchPayload throws this CommandExecutionError when the Zhihu search response carries __httpError with a status other than 401/403 (e.g. 429, 500). The message includes the HTTP status code when known; the remedy hints at retrying later or using -v for detail. It means Zhihu's server rejected the search request at the HTTP level.","triggerScenarios":"The in-page fetch of Zhihu's search endpoint returned any non-2xx status other than 401/403 — e.g. 429 (rate limited), 5xx (server error), 404 (endpoint changed) — stored as payload.__httpError.","commonSituations":"Hammering the search endpoint with rapid repeated queries (429); Zhihu server-side incident (5xx); Zhihu changing its search API path (404); transient network proxies returning error statuses.","solutions":["Wait and retry with backoff — 429/5xx are usually temporary","Rerun with -v to capture the exact HTTP status and diagnose","Reduce search frequency and lower --limit to stay under risk-control thresholds","If status is 404 consistently, update the CLI — the Zhihu search endpoint likely changed","Log in via the connected Chrome profile to raise rate limits"],"exampleFix":"// before: immediate retry\nawait searchZhihu(q);\n// after\ncatch (err) {\n  if (err instanceof CommandExecutionError && /HTTP 429/.test(err.message)) {\n    await sleep(30_000);\n    return searchZhihu(q);\n  }\n  throw err;\n}","handlingStrategy":"retry","validationCode":"// throttle before calling\nconst MIN_INTERVAL_MS = 2000;\nawait sleep(Math.max(0, lastCallAt + MIN_INTERVAL_MS - Date.now()));","typeGuard":"function isHttpFailure(err) {\n  return err instanceof CommandExecutionError && /Zhihu search request failed/.test(err.message);\n}","tryCatchPattern":"try {\n  return await searchZhihu(q);\n} catch (err) {\n  if (isHttpFailure(err) && /HTTP 429|HTTP 5/.test(err.message)) {\n    await sleep(30_000);\n    return searchZhihu(q); // bounded exponential backoff in production\n  }\n  throw err;\n}","preventionTips":["Rate-limit searches (e.g. one every few seconds) to avoid 429s","Keep --limit modest (≤20) to reduce server strain","Add exponential backoff with a retry cap around search calls","Monitor for persistent 404s which indicate an endpoint/API change needing a CLI update"],"tags":["zhihu","http-error","rate-limit","network"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}