{"record":{"id":"7199eb3dec86f847","repo":"chenhg5/cc-connect","slug":"get-token-w","errorCode":null,"errorMessage":"get token: %w","messagePattern":"get token: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":882,"sourceCode":"\tif len(data) >= 6 {\n\t\thead := string(data[:6])\n\t\tif head == \"GIF87a\" || head == \"GIF89a\" {\n\t\t\treturn \"image/gif\"\n\t\t}\n\t}\n\tif len(data) >= 12 && string(data[:4]) == \"RIFF\" && string(data[8:12]) == \"WEBP\" {\n\t\treturn \"image/webp\"\n\t}\n\tif len(data) >= 4 && string(data[:4]) == \"%PDF\" {\n\t\treturn \"application/pdf\"\n\t}\n\treturn \"\"\n}\n\nfunc (p *Platform) downloadMedia(mediaID string) ([]byte, error) {\n\taccessToken, err := p.getAccessToken()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get token: %w\", err)\n\t}\n\tu := p.wecomAPIURL(\"/cgi-bin/media/get\", url.Values{\n\t\t\"access_token\": []string{accessToken},\n\t\t\"media_id\":     []string{mediaID},\n\t})\n\tresp, err := p.apiClient.Get(u)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"download: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\treturn io.ReadAll(resp.Body)\n}\n","sourceCodeStart":864,"sourceCodeEnd":895,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L864-L895","documentation":"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.","triggerScenarios":"Thrown at platform/wecom/wecom.go:882 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the chained error to distinguish network failure (retry) from credential errors (fix config)","On token-expiry races, retry once — a concurrent refresh may have already renewed it","Log with the underlying cause preserved via the %w chain"],"exampleFix":null,"handlingStrategy":"try-catch","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"}