{"record":{"id":"f8fcc52326e9df43","repo":"chenhg5/cc-connect","slug":"wecom-get-token-failed-d-s","errorCode":null,"errorMessage":"wecom: get token failed: %d %s","messagePattern":"wecom: get token failed: (.+?) (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":686,"sourceCode":"\t})\n\n\tresp, err := p.apiClient.Get(apiURL)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: request access_token: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tvar result struct {\n\t\tErrCode     int    `json:\"errcode\"`\n\t\tErrMsg      string `json:\"errmsg\"`\n\t\tAccessToken string `json:\"access_token\"`\n\t\tExpiresIn   int    `json:\"expires_in\"`\n\t}\n\tif err := json.NewDecoder(resp.Body).Decode(&result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"wecom: decode token response: %w\", err)\n\t}\n\tif result.ErrCode != 0 {\n\t\treturn \"\", fmt.Errorf(\"wecom: get token failed: %d %s\", result.ErrCode, result.ErrMsg)\n\t}\n\n\t// Compute the cache window from expires_in with a 60-second safety\n\t// margin. When the server omits or zeroes the field, fall back to\n\t// WeCom's documented 7200s default; without this, the raw value would\n\t// land at -60 and the cache would be stale on the very next call,\n\t// turning every outbound API request into a fresh /gettoken round-trip.\n\texpires := result.ExpiresIn\n\tif expires <= 0 {\n\t\tslog.Warn(\"wecom: missing/invalid expires_in in token response, defaulting to 7200s\", \"got\", result.ExpiresIn)\n\t\texpires = 7200\n\t}\n\tif expires > 60 {\n\t\texpires -= 60\n\t}\n\tp.tokenCache.token = result.AccessToken\n\tp.tokenCache.expiresAt = time.Now().Add(time.Duration(expires) * time.Second)\n","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L668-L704","documentation":"WeCom API rejection of the token request: the gettoken response parsed but errcode was non-zero. Classic codes: 40013 invalid corpid, 40125 invalid corpsecret, 40029 bad appid/secret pair. This is a credential/configuration error surfaced at token-fetch time and affects every subsequent API call.","triggerScenarios":"Thrown at platform/wecom/wecom.go:686 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify corp_id and corp_secret in config.toml against the WeCom admin console","Confirm the secret belongs to the same app/agent as agentid","Redact the secret from any logs (core.RedactToken)","Do not hot-retry invalid-credential errors; fail fast with a clear i18n message"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}