chenhg5/cc-connect · error

wecom: decode send image response: %w

Error message

wecom: decode send image response: %w

What it means

JSON decode failure while reading the WeCom message/send API response body for an image send: the server returned a non-JSON body (gateway error page, empty body) so the errcode/errmsg envelope could not be parsed.

Source

Thrown at platform/wecom/wecom.go:534

	}

	body, _ := json.Marshal(payload)
	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)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Log a snippet of the raw body to identify what the server actually returned
  2. Retry once — transient gateway responses frequently decode fine on the next attempt
  3. If a WAF/proxy sits in front of qyapi.weixin.qq.com, whitelist it for the API host
  4. Verify the access_token was appended correctly; some auth failures return non-JSON bodies
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at platform/wecom/wecom.go:534 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/97706631c00f0870. Report an issue: GitHub.