chenhg5/cc-connect · error
wecom: decode token response: %w
Error message
wecom: decode token response: %w
What it means
JSON parse failure on the gettoken response: the server replied but the body could not be decoded into {errcode, errmsg, access_token, expires_in}. Usually means an HTML error page, an auth-redirect body, or a truncated response arrived instead of the API's JSON envelope.
Source
Thrown at platform/wecom/wecom.go:683
apiURL := p.wecomAPIURL("/cgi-bin/gettoken", url.Values{
"corpid": []string{p.corpID},
"corpsecret": []string{p.corpSecret},
})
resp, err := p.apiClient.Get(apiURL)
if err != nil {
return "", fmt.Errorf("wecom: request access_token: %w", err)
}
defer resp.Body.Close()
var result struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("wecom: decode token response: %w", err)
}
if result.ErrCode != 0 {
return "", fmt.Errorf("wecom: get token failed: %d %s", result.ErrCode, result.ErrMsg)
}
// Compute the cache window from expires_in with a 60-second safety
// margin. When the server omits or zeroes the field, fall back to
// WeCom's documented 7200s default; without this, the raw value would
// land at -60 and the cache would be stale on the very next call,
// turning every outbound API request into a fresh /gettoken round-trip.
expires := result.ExpiresIn
if expires <= 0 {
slog.Warn("wecom: missing/invalid expires_in in token response, defaulting to 7200s", "got", result.ExpiresIn)
expires = 7200
}
if expires > 60 {
expires -= 60
}View on GitHub (pinned to 4000b2338a)
Solutions
- Log the raw response body and Content-Type to identify what was returned
- Retry once; gateway glitches are frequently transient
- Check for a man-in-the-middle/proxy rewriting responses
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at platform/wecom/wecom.go:683 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/290377d177c8a290.
Report an issue: GitHub.