{"record":{"id":"1b0804a7e5421784","repo":"chenhg5/cc-connect","slug":"s-cdn-upload-server-error-s","errorCode":null,"errorMessage":"%s: CDN upload server error: %s","messagePattern":"(.+?): CDN upload server error: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/weixin/cdn.go","lineNumber":210,"sourceCode":"\t\t\tlastErr = err\n\t\t\tslog.Warn(\"weixin: CDN upload request failed\", \"label\", label, \"attempt\", attempt, \"error\", err)\n\t\t\tcontinue\n\t\t}\n\t\t_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 4096))\n\t\t_ = resp.Body.Close()\n\t\tif resp.StatusCode >= 400 && resp.StatusCode < 500 {\n\t\t\tmsg := resp.Header.Get(\"x-error-message\")\n\t\t\tif msg == \"\" {\n\t\t\t\tmsg = resp.Status\n\t\t\t}\n\t\t\treturn \"\", fmt.Errorf(\"%s: CDN upload client error %d: %s\", label, resp.StatusCode, msg)\n\t\t}\n\t\tif resp.StatusCode != http.StatusOK {\n\t\t\tmsg := resp.Header.Get(\"x-error-message\")\n\t\t\tif msg == \"\" {\n\t\t\t\tmsg = fmt.Sprintf(\"status %d\", resp.StatusCode)\n\t\t\t}\n\t\t\tlastErr = fmt.Errorf(\"%s: CDN upload server error: %s\", label, msg)\n\t\t\tslog.Warn(\"weixin: CDN upload server error\", \"label\", label, \"attempt\", attempt, \"error\", lastErr)\n\t\t\tcontinue\n\t\t}\n\t\tdl := resp.Header.Get(\"x-encrypted-param\")\n\t\tif dl == \"\" {\n\t\t\tlastErr = fmt.Errorf(\"%s: CDN response missing x-encrypted-param\", label)\n\t\t\tslog.Warn(\"weixin: CDN upload bad response\", \"label\", label, \"attempt\", attempt)\n\t\t\tcontinue\n\t\t}\n\t\treturn dl, nil\n\t}\n\tif lastErr != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: CDN upload failed after %d attempts: %w\", label, cdnUploadMaxRetries, lastErr)\n\t}\n\treturn \"\", fmt.Errorf(\"%s: CDN upload failed after %d attempts\", label, cdnUploadMaxRetries)\n}\n\nfunc md5Hex(b []byte) string {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/cdn.go#L192-L228","documentation":"uploadBufferToCDN records this error when the CDN returns a 5xx (or any non-200 outside 400-499) status. It is stored as lastErr and the loop retries up to cdnUploadMaxRetries (3) attempts before surfacing the wrapped error via the 'failed after N attempts' message. The reason is taken from the x-error-message header or 'status <code>'.","triggerScenarios":"Any CDN upload POST returning HTTP >= 500 (or non-200 outside 400-499), e.g. 500, 502, 503 from the CDN edge; each attempt logs slog.Warn then continues.","commonSituations":"Transient CDN outages or capacity issues; CDN edge nodes returning 502/504; maintenance windows on novac2c.cdn.weixin.qq.com.","solutions":["Retry the operation — server errors are transient and the function already retries 3 times; the wrapped lastErr shows the final reason","Check the x-error-message/status in the error text for the specific 5xx code","Verify network connectivity and DNS resolution to the CDN host","If persistent, check WeChat service status or reduce media size/frequency"],"exampleFix":"// before: treating every upload failure as fatal\nif err := uploadToWeixinCDN(ctx, ...); err != nil { return err }\n// after: tolerate transient server errors with backoff at the caller\nif err := uploadToWeixinCDN(ctx, ...); err != nil {\n    if strings.Contains(err.Error(), \"server error\") { time.Sleep(time.Second); return uploadToWeixinCDN(ctx, ...) }\n    return err\n}","handlingStrategy":"retry","validationCode":"// check reachability before a batch of uploads\nresp, err := http.Get(\"https://novac2c.cdn.weixin.qq.com/c2c/healthz\") // or any cheap probe\nif err != nil { /* defer uploads or use fallback */ }","typeGuard":null,"tryCatchPattern":"// the library already retries 3x; add caller backoff\nif err != nil && strings.Contains(err.Error(), \"CDN upload server error\") {\n    time.Sleep(2 * time.Second)\n    // retry once more\n}","preventionTips":["Treat 5xx as transient and add exponential backoff at the call site","Spread large media uploads over time to avoid CDN-side throttling","Monitor for repeated server errors and alert on sustained CDN degradation","Keep the official cdn_base so requests hit healthy endpoints"],"tags":["http","cdn","upload","server-error","retry"],"backgroundTag":"http-error-response","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"}