{"record":{"id":"0914c4f0203e3330","repo":"chenhg5/cc-connect","slug":"decode-w","errorCode":null,"errorMessage":"decode: %w","messagePattern":"decode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/setup.go","lineNumber":251,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar result map[string]any\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode: %w\", err)\n\t}\n\treturn result, nil\n}\n\n// ── Weixin (ilink) QR Setup ─────────────────────────────────\n\nfunc (m *ManagementServer) handleSetupWeixinBegin(w http.ResponseWriter, r *http.Request) {\n\tif r.Method != http.MethodPost {\n\t\tmgmtError(w, http.StatusMethodNotAllowed, \"POST only\")\n\t\treturn\n\t}\n\n\tvar req struct {\n\t\tAPIURL string `json:\"api_url\"`\n\t}\n\t_ = json.NewDecoder(r.Body).Decode(&req)\n\n\tapiBase := weixinDefaultAPIURL","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/setup.go#L233-L269","documentation":"feishuRegistrationCall wraps JSON decoding failures of the Feishu registration/setup API response body with \"decode: %w\". The HTTP call succeeded and returned a body, but the body is not valid JSON or does not match map[string]any. Callers handleSetupFeishuBegin and handleSetupFeishuPoll surface this to the user as a setup failure.","triggerScenarios":"The Feishu API endpoint returns HTML (login/error page), an empty body, a proxy interception page, or malformed JSON instead of the expected JSON object during QR setup begin/poll.","commonSituations":"Corporate proxy or captive portal injecting HTML; Feishu API outage returning an error page; wrong base URL configured pointing at a non-API host; intermittent network truncation of the response body.","solutions":["Log the raw response body (feishuRegistrationCall has it in `body`) to see what was actually returned","Verify the Feishu API base URL and that the endpoint returns application/json","Retry the setup flow; if behind a proxy, bypass it for the API host","Check network/DNS health and Feishu service status before re-running setup"],"exampleFix":"// before\nresult, err := feishuRegistrationCall(ctx, \"/qr/setup\")\n// after\nresult, err := feishuRegistrationCall(ctx, \"/qr/setup\")\nif err != nil {\n    slog.Error(\"feishu setup failed\", \"err\", err, \"endpoint\", \"/qr/setup\")\n    return fmt.Errorf(\"feishu setup: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"resp, err := http.Get(url)\nif err == nil {\n    ct := resp.Header.Get(\"Content-Type\")\n    if !strings.Contains(ct, \"application/json\") {\n        slog.Warn(\"unexpected content-type from feishu api\", \"content_type\", ct)\n    }\n    b, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n    if !json.Valid(b) { slog.Warn(\"feishu api returned invalid JSON\") }\n}","typeGuard":"func looksLikeJSON(body []byte) bool {\n    t := bytes.TrimSpace(body)\n    return len(t) > 0 && (t[0] == '{' || t[0] == '[')\n}","tryCatchPattern":"result, err := feishuRegistrationCall(ctx, path)\nif err != nil {\n    var decodeErr *json.SyntaxError\n    if strings.HasPrefix(err.Error(), \"decode:\") || errors.As(err, &decodeErr) {\n        slog.Error(\"feishu setup: non-JSON API response (proxy/HTML page?)\", \"err\", err)\n    }\n    return err\n}","preventionTips":["Verify the Feishu API base URL and endpoints return application/json","Log the raw body on decode failure to spot HTML/proxy pages","Test setup flows behind corporate proxies/captive portals before rollout"],"tags":["json","http","feishu","setup"],"backgroundTag":"json-unmarshal-failed","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"}