chenhg5/cc-connect · error
wecom: send image failed: %d %s
Error message
wecom: send image failed: %d %s
What it means
WeCom API application-level rejection of the image message send: the response parsed as JSON but errcode was non-zero, with errmsg describing why. Common codes: 40014/42001 invalid or expired access_token, 45009 rate limit exceeded, 81013 invalid touser, or invalid media_id from a failed upload.
Source
Thrown at platform/wecom/wecom.go:537
apiURL := p.wecomAPIURL("/cgi-bin/message/send", url.Values{
"access_token": []string{accessToken},
})
resp, err := p.apiClient.Post(apiURL, "application/json", strings.NewReader(string(body)))
if err != nil {
return fmt.Errorf("wecom: send image: %w", err)
}
defer resp.Body.Close()
var result struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return fmt.Errorf("wecom: decode send image response: %w", err)
}
if result.ErrCode != 0 {
return fmt.Errorf("wecom: send image failed: %d %s", result.ErrCode, result.ErrMsg)
}
return nil
}
// uploadImageMedia uploads an image to WeChat Work media API and returns the media_id.
func (p *Platform) uploadImageMedia(accessToken string, img core.ImageAttachment) (string, error) {
name := img.FileName
if name == "" {
name = "image.png"
}
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("media", name)
if err != nil {
return "", fmt.Errorf("wecom: create form file: %w", err)
}View on GitHub (pinned to 4000b2338a)
Solutions
- For 40014/42001, force a token refresh (clear tokenCache) and resend once
- For 45009, back off and respect the rate limit before retrying
- For invalid media_id, re-upload the image via uploadImageMedia and retry the send
- Map frequent errcodes to user-visible i18n messages instead of leaking raw codes
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at platform/wecom/wecom.go:537 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/057a569a668f7475.
Report an issue: GitHub.