chenhg5/cc-connect · error

get token: %w

Error message

get token: %w

What it means

Wrap in downloadMedia of a getAccessToken failure: the cached token was expired/absent and fetching a new one failed (the underlying cause — transport error, invalid credentials, or API errcode — is chained in the wrapped error). Media download cannot proceed without the token, so the whole fetch aborts.

Source

Thrown at platform/wecom/wecom.go:882

	if len(data) >= 6 {
		head := string(data[:6])
		if head == "GIF87a" || head == "GIF89a" {
			return "image/gif"
		}
	}
	if len(data) >= 12 && string(data[:4]) == "RIFF" && string(data[8:12]) == "WEBP" {
		return "image/webp"
	}
	if len(data) >= 4 && string(data[:4]) == "%PDF" {
		return "application/pdf"
	}
	return ""
}

func (p *Platform) downloadMedia(mediaID string) ([]byte, error) {
	accessToken, err := p.getAccessToken()
	if err != nil {
		return nil, fmt.Errorf("get token: %w", err)
	}
	u := p.wecomAPIURL("/cgi-bin/media/get", url.Values{
		"access_token": []string{accessToken},
		"media_id":     []string{mediaID},
	})
	resp, err := p.apiClient.Get(u)
	if err != nil {
		return nil, fmt.Errorf("download: %w", err)
	}
	defer resp.Body.Close()
	return io.ReadAll(resp.Body)
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the chained error to distinguish network failure (retry) from credential errors (fix config)
  2. On token-expiry races, retry once — a concurrent refresh may have already renewed it
  3. Log with the underlying cause preserved via the %w chain
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at platform/wecom/wecom.go:882 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/7199eb3dec86f847. Report an issue: GitHub.