{"record":{"id":"d95adfadb4c5495a","repo":"chenhg5/cc-connect","slug":"invalid-json-response-w","errorCode":null,"errorMessage":"invalid json response: %w","messagePattern":"invalid json response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/weixin.go","lineNumber":539,"sourceCode":"\t}\n\tdefer resp.Body.Close()\n\traw, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n\tif err != nil {\n\t\treturn err\n\t}\n\tif debug {\n\t\tsnippet := string(raw)\n\t\tif len(snippet) > 300 {\n\t\t\tsnippet = snippet[:300]\n\t\t}\n\t\tfmt.Fprintf(os.Stderr, \"[debug] verify getUpdates -> %d %s\\n\", resp.StatusCode, strings.TrimSpace(snippet))\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"http %d: %s\", resp.StatusCode, weixinTruncateBody(raw, 256))\n\t}\n\tvar parsed map[string]any\n\tif err := json.Unmarshal(raw, &parsed); err != nil {\n\t\treturn fmt.Errorf(\"invalid json response: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc randomWeixinUIN() string {\n\tvar b [4]byte\n\tif _, err := rand.Read(b[:]); err != nil {\n\t\treturn base64.StdEncoding.EncodeToString([]byte(\"0000\"))\n\t}\n\tu := uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])\n\treturn base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf(\"%d\", u)))\n}\n\nfunc printWeixinUsage() {\n\tfmt.Println(`Usage: cc-connect weixin <command> [options]\n\nCommands:\n  setup   QR login when no --token; with --token => bind existing ilink bot token","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/weixin.go#L521-L557","documentation":"verifyWeixinToken decodes the 200 response into a generic map[string]any to confirm it is well-formed JSON. If json.Unmarshal fails, verification fails with this error. The endpoint returned 200 but the body was not parseable JSON, so the token's validity cannot be confirmed.","triggerScenarios":"Token verification GET returns HTTP 200 with an HTML page, empty body, or malformed JSON instead of the expected JSON object.","commonSituations":"Intercepting proxy or wrong port returning a 200 HTML page; api_base misconfiguration pointing at a non-API service; middleboxes that fake success responses.","solutions":["Dump the raw response body to see what was returned","Verify the api_base scheme/host/port actually hosts the WeChat bot API","Disable or bypass intercepting proxies/VPN for this request","Retry — intermittent HTML error pages from a load balancer can produce this"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if !json.Valid(raw) {\n    return fmt.Errorf(\"verify: non-JSON 200 response: %.100s\", raw)\n}","typeGuard":"func isJSONObject(b []byte) bool {\n    var v map[string]any\n    return json.Unmarshal(b, &v) == nil && v != nil\n}","tryCatchPattern":"if err := verifyWeixinToken(ctx, apiBase, token, routeTag, debug); err != nil {\n    if strings.Contains(err.Error(), \"invalid json response\") {\n        return fmt.Errorf(\"weixin: api_base %s did not return JSON — check the URL\", apiBase)\n    }\n    return err\n}","preventionTips":["Verify api_base host/scheme/port before setup","Bypass intercepting proxies for verification calls","Dump raw bodies on verification failure","Prefer HTTPS endpoints you control or trust"],"tags":["json","unmarshal","weixin","token","verification"],"backgroundTag":"invalid-json-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}