chenhg5/cc-connect · error

%s: get: %w

Error message

%s: get: %w

What it means

The HTTP client failed to execute the CDN GET request in fetchCdnBytes — a transport-level failure (connection refused/reset, DNS, timeout, or context cancellation) while downloading Weixin CDN media bytes, before any status code was received.

Source

Thrown at platform/weixin/cdn.go:135

func buildCdnUploadURL(cdnBase, uploadParam, filekey string) string {
	return fmt.Sprintf("%s/upload?encrypted_query_param=%s&filekey=%s",
		strings.TrimRight(cdnBase, "/"),
		url.QueryEscape(uploadParam),
		url.QueryEscape(filekey))
}

func fetchCdnBytes(ctx context.Context, client *http.Client, fullURL, label string) ([]byte, error) {
	if client == nil {
		client = http.DefaultClient
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil)
	if err != nil {
		return nil, fmt.Errorf("%s: new request: %w", label, err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("%s: get: %w", label, err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(io.LimitReader(resp.Body, maxWeixinMediaBytes+1))
	if err != nil {
		return nil, fmt.Errorf("%s: read: %w", label, err)
	}
	if len(body) > maxWeixinMediaBytes {
		return nil, fmt.Errorf("%s: CDN body exceeds %d bytes", label, maxWeixinMediaBytes)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: CDN http %d: %s", label, resp.StatusCode, truncateForLog(body, 256))
	}
	return body, nil
}

func downloadAndDecryptCDN(ctx context.Context, client *http.Client, cdnBase, encParam, aesKeyBase64, label string) ([]byte, error) {
	key, err := parseAesKey(aesKeyBase64, label)
	if err != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the download with limited attempts and backoff; CDN endpoints are often transiently unavailable
  2. Configure a reasonable timeout on the http.Client used for CDN fetches
  3. Abort cleanly when the parent context is cancelled (user message flow already torn down)
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at platform/weixin/cdn.go:135 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/bd750219f1b4c7b9. Report an issue: GitHub.