{"record":{"id":"0e3a1a348caf5486","repo":"chenhg5/cc-connect","slug":"s-create-card-entity-parse-response-w","errorCode":null,"errorMessage":"%s: create card entity: parse response: %w","messagePattern":"(.+?): create card entity: parse response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":5187,"sourceCode":"\tif err := p.withFreshTenantAccessTokenRetry(ctx, \"create card entity\", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {\n\t\tvar err error\n\t\tapiResp, err = client.Post(ctx, \"/open-apis/cardkit/v1/cards\", body, larkcore.AccessTokenTypeTenant, options...)\n\t\treturn err\n\t}); err != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: create card entity: %w\", p.tag(), err)\n\t}\n\tif apiResp == nil || apiResp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"%s: create card entity: HTTP status %d\", p.tag(), apiResp.StatusCode)\n\t}\n\tvar resp struct {\n\t\tCode int    `json:\"code\"`\n\t\tMsg  string `json:\"msg\"`\n\t\tData struct {\n\t\t\tCardID string `json:\"card_id\"`\n\t\t} `json:\"data\"`\n\t}\n\tif err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: create card entity: parse response: %w\", p.tag(), err)\n\t}\n\tif resp.Code != 0 {\n\t\treturn \"\", fmt.Errorf(\"%s: %w\", p.tag(), classifyFeishuCardAPIError(\"create card entity\", resp.Code, resp.Msg))\n\t}\n\tif resp.Data.CardID == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%s: create card entity: empty card_id in response\", p.tag())\n\t}\n\treturn resp.Data.CardID, nil\n}\n\n// StreamRichCardText implements core.RichCardTextStreamer. Pushes the latest\n// fullText to the rich card's main_text element via cardkit-v1 streaming text\n// update API. The Lark client renders the increment between consecutive PUTs\n// with a typewriter animation (controlled by the card's streaming_config).\n//\n// Returns ErrNotSupported when the handle has no cardID (preview was created\n// via the inline-card-JSON fallback path; engine should fall back to full-card\n// Patch).","sourceCodeStart":5169,"sourceCodeEnd":5205,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L5169-L5205","documentation":"The cardkit Create Card Entity API returned HTTP 200 but its RawBody could not be unmarshaled into the expected {code,msg,data:{card_id}} shape. Indicates the body is not the JSON the Cardkit v1 API documents — usually a gateway/auth page, truncated body, or an SDK RawBody issue.","triggerScenarios":"json.Unmarshal(apiResp.RawBody, &resp) fails: the endpoint returned HTML (proxy login/error page), an empty body, or JSON whose data/card_id fields have incompatible types (e.g. card_id as a number).","commonSituations":"Corporate MITM proxy returning an auth page; misconfigured base URL pointing at a non-Feishu service; unexpected Feishu API version change altering response field types; truncated response from an aggressive intermediary.","solutions":["Log string(apiResp.RawBody) to see what was actually returned","Verify the API base URL points to the real Feishu/Lark endpoint and no proxy rewrites it","Upgrade the larksuite SDK so RawBody handling matches the current client","If a Feishu schema change renamed fields, update the inline response struct"],"exampleFix":"// before\nvar resp struct {\n\tCode int    `json:\"code\"`\n\tMsg  string `json:\"msg\"`\n\tData struct {\n\t\tCardID string `json:\"card_id\"`\n\t} `json:\"data\"`\n}\n// after\nif len(apiResp.RawBody) == 0 {\n\treturn \"\", fmt.Errorf(\"%s: create card entity: empty response body\", p.tag())\n}\nvar resp struct {\n\tCode int    `json:\"code\"`\n\tMsg  string `json:\"msg\"`\n\tData struct {\n\t\tCardID string `json:\"card_id\"`\n\t} `json:\"data\"`\n}","handlingStrategy":"validation","validationCode":"if apiResp == nil || len(apiResp.RawBody) == 0 {\n\treturn fmt.Errorf(\"empty cardkit response\")\n}\nif apiResp.RawBody[0] != '{' {\n\treturn fmt.Errorf(\"non-JSON cardkit response (proxy?)\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tvar unmarshalErr *json.UnmarshalTypeError\n\tif errors.As(err, &unmarshalErr) {\n\t\t// log RawBody; fall back to inline-card JSON send\n\t}\n}","preventionTips":["Ensure no MITM proxy intercepts open.feishu.cn traffic","Log RawBody on every parse failure","Pin the Feishu API endpoint (feishu vs larksuite) to the app's region","Upgrade the SDK when Feishu announces schema changes"],"tags":["feishu","cardkit","json","response-parsing"],"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"}