{"record":{"id":"5240c15194027c57","repo":"jackwener/OpenCLI","slug":"sina-finance-rolling-news-api-returned-invalid-jso","errorCode":null,"errorMessage":"Sina Finance rolling news API returned invalid JSON: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Sina Finance rolling news API returned invalid JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/sinafinance/rolling-news.js","lineNumber":86,"sourceCode":"            num: '50',\n            page: '1',\n        });\n        let response;\n        try {\n            response = await fetch(`${ROLL_API}?${params}`);\n        }\n        catch (error) {\n            throw new CommandExecutionError(`Sina Finance rolling news request failed: ${error instanceof Error ? error.message : String(error)}`);\n        }\n        if (!response.ok) {\n            throw new CommandExecutionError(`Sina Finance rolling news API returned HTTP ${response.status}`);\n        }\n        let payload;\n        try {\n            payload = await response.json();\n        }\n        catch (error) {\n            throw new CommandExecutionError(`Sina Finance rolling news API returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`);\n        }\n        return normalizeRollRows(payload);\n    },\n});\n","sourceCodeStart":68,"sourceCodeEnd":91,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/sinafinance/rolling-news.js#L68-L91","documentation":"CommandExecutionError thrown when response.json() rejects because the body is not valid JSON. The underlying parse error message is interpolated. This means the HTTP call succeeded but the body was HTML, empty, or otherwise non-JSON.","triggerScenarios":"Sina (or a middlebox) returns an HTML error/login page with HTTP 200, an empty body, truncated responses, or gzip-encoding mismatches that make the body unparseable.","commonSituations":"Captive portals or proxies intercepting the response; Sina serving an anti-bot HTML page with status 200; CDN edge errors emitting partial bodies; network truncation on flaky connections.","solutions":["Log the raw response text to see what was actually returned","Check for proxy/VPN interference rewriting the body","Retry — truncated bodies are often transient","If Sina changed content-type/encoding, adjust the client's Accept headers"],"exampleFix":"// before\nconst text = await response.text();\nconsole.log(text); // <html>... anti-bot page\n// after\n// disable interfering proxy or add browser-like headers\nconst res = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0', Referer: 'https://finance.sina.com.cn' } });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const rows = await cli.rollingNews();\n} catch (err) {\n  if (/invalid JSON/.test(err.message)) {\n    // body wasn't JSON: likely HTML error page or proxy interference\n    console.error('Non-JSON body from Sina; check proxy/anti-bot interception');\n    return retryWithBackoff(() => cli.rollingNews(), 2);\n  }\n  throw err;\n}","preventionTips":["Bypass captive portals/proxies when calling the CLI","Send browser-like headers (User-Agent, Referer) to avoid anti-bot HTML pages","Retry on parse failures — truncation is often transient","Log raw response text on failure to confirm what was returned"],"tags":["json","parse-error","malformed-response"],"backgroundTag":"invalid-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}