chenhg5/cc-connect · error
wecom: decode upload response: %w
Error message
wecom: decode upload response: %w
What it means
JSON parse failure on the /cgi-bin/media/upload response: the server responded but the body is not the expected {errcode, errmsg, media_id} JSON — commonly an HTML gateway error page, a truncated response, or an intermediate proxy response.
Source
Thrown at platform/wecom/wecom.go:579
}
apiURL := p.wecomAPIURL("/cgi-bin/media/upload", url.Values{
"access_token": []string{accessToken},
"type": []string{"image"},
})
resp, err := p.apiClient.Post(apiURL, writer.FormDataContentType(), body)
if err != nil {
return "", fmt.Errorf("wecom: upload image: %w", err)
}
defer resp.Body.Close()
var result struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
MediaID string `json:"media_id"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("wecom: decode upload response: %w", err)
}
if result.ErrCode != 0 {
return "", fmt.Errorf("wecom: upload image failed: %d %s", result.ErrCode, result.ErrMsg)
}
if result.MediaID == "" {
return "", fmt.Errorf("wecom: upload image: empty media_id")
}
return result.MediaID, nil
}
var _ core.ImageSender = (*Platform)(nil)
func (p *Platform) sendMarkdown(accessToken, toUser, content string) error {
payload := map[string]any{
"touser": toUser,
"msgtype": "markdown",
"agentid": p.agentID,
"markdown": map[string]string{"content": content},View on GitHub (pinned to 4000b2338a)
Solutions
- Capture and log the raw body prefix to identify the non-JSON payload
- Retry once; transient gateway responses often clear immediately
- Check proxy/WAF interference on the API host
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at platform/wecom/wecom.go:579 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/a3fd8663da71943c.
Report an issue: GitHub.