{"record":{"id":"290377d177c8a290","repo":"chenhg5/cc-connect","slug":"wecom-decode-token-response-w","errorCode":null,"errorMessage":"wecom: decode token response: %w","messagePattern":"wecom: decode token response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":683,"sourceCode":"\tapiURL := p.wecomAPIURL(\"/cgi-bin/gettoken\", url.Values{\n\t\t\"corpid\":     []string{p.corpID},\n\t\t\"corpsecret\": []string{p.corpSecret},\n\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}","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L665-L701","documentation":"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.","triggerScenarios":"Thrown at platform/wecom/wecom.go:683 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"retry","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-14T00:17:10.932Z"}