{"record":{"id":"46a1241b64c9f81e","repo":"chenhg5/cc-connect","slug":"upload-request-w","errorCode":null,"errorMessage":"upload request: %w","messagePattern":"upload request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/dingtalk/dingtalk.go","lineNumber":1372,"sourceCode":"\n\tif _, err := part.Write(data); err != nil {\n\t\treturn \"\", fmt.Errorf(\"write media data: %w\", err)\n\t}\n\n\tif err := writer.Close(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"close multipart writer: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, uploadURL, body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"create upload request: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tresp, err := p.httpClient.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"upload request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read upload response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"upload returned status %d: %s\", resp.StatusCode, respBody)\n\t}\n\n\tslog.Debug(\"dingtalk: media upload response\", \"status\", resp.StatusCode, \"body\", string(respBody))\n\n\tvar uploadResp struct {\n\t\tErrCode int    `json:\"errcode\"`\n\t\tErrMsg  string `json:\"errmsg\"`\n\t\tMediaID string `json:\"media_id\"`","sourceCodeStart":1354,"sourceCodeEnd":1390,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L1354-L1390","documentation":"The HTTP transport itself failed when POSTing the multipart media upload to the DingTalk API — the request never got a usable response. p.httpClient.Do returned an error such as DNS failure, TCP connect refused/timeout, TLS error, or context cancellation.","triggerScenarios":"uploadMedia calls p.httpClient.Do(req) for https://oapi.dingtalk.com/media/upload and the network layer errors before/without an HTTP status line.","commonSituations":"No outbound internet access or DNS failure on the host; corporate proxy/firewall blocking oapi.dingtalk.com; TLS interception with an untrusted CA; context deadline exceeded because upload of a big media file was too slow; daemon run in an isolated container network.","solutions":["Verify connectivity: curl -v https://oapi.dingtalk.com/media/upload from the host.","Check proxy/HTTPS_PROXY settings and corporate CA certs (SSL_CERT_FILE/SSL_CERT_DIR).","Increase the httpClient timeout or pass a longer-lived context for large media uploads.","Retry with backoff for transient DNS/connect failures; alert on persistent network loss."],"exampleFix":"// before\nresp, err := p.httpClient.Do(req)\nif err != nil { return \"\", fmt.Errorf(\"upload request: %w\", err) }\n// after\nresp, err := p.httpClient.Do(req)\nif err != nil {\n    if ctx.Err() != nil { return \"\", fmt.Errorf(\"upload canceled: %w\", ctx.Err()) }\n    return \"\", retryable(fmt.Errorf(\"upload request: %w\", err))\n}","handlingStrategy":"retry","validationCode":"// Pre-flight connectivity check\nresp, err := http.Head(\"https://oapi.dingtalk.com\")\nif err != nil { return fmt.Errorf(\"dingtalk unreachable: %w\", err) }\nresp.Body.Close()","typeGuard":null,"tryCatchPattern":"resp, err := p.httpClient.Do(req)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { return \"\", err }\n    return \"\", retryWithBackoff(err) // transient network error\n}","preventionTips":["Set a generous httpClient timeout for media uploads.","Configure proxy/CA env vars correctly in containerized deployments.","Add retry with exponential backoff for transient transport errors.","Include DingTalk endpoint reachability in startup health checks."],"tags":["dingtalk","network","http","upload"],"backgroundTag":"network-request-failed","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"}