chenhg5/cc-connect · error

do request: %w

Error message

do request: %w

What it means

getDownloadURL wraps a transport-level failure of the POST to DingTalk's messageFiles/download API. The request was built and sent but p.httpClient.Do returned an error: connection failure, DNS, TLS, or the 30-second context timeout expired.

Source

Thrown at platform/dingtalk/dingtalk.go:703

	if err != nil {
		return "", fmt.Errorf("marshal request: %w", err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()
	req, err := http.NewRequestWithContext(ctx, http.MethodPost,
		"https://api.dingtalk.com/v1.0/robot/messageFiles/download",
		bytes.NewReader(bodyBytes))
	if err != nil {
		return "", fmt.Errorf("create request: %w", err)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("x-acs-dingtalk-access-token", token)

	resp, err := p.httpClient.Do(req)
	if err != nil {
		return "", fmt.Errorf("do request: %w", err)
	}
	defer func() { _ = resp.Body.Close() }()

	if resp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("api returned status %d", resp.StatusCode)
	}

	var result downloadResponse
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return "", fmt.Errorf("decode response: %w", err)
	}

	if result.DownloadUrl == "" {
		return "", fmt.Errorf("empty downloadUrl in response")
	}

	return result.DownloadUrl, nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Test connectivity to https://api.dingtalk.com from the host (curl the endpoint).
  2. Check proxy/firewall rules and HTTP(S)_PROXY environment variables affecting the Go HTTP client.
  3. Check the wrapped cause for 'context deadline exceeded' — if timeouts recur, review network latency or proxying to DingTalk.
  4. Retry with backoff for transient network errors.
Defensive patterns

Strategy: retry

Validate before calling

// Startup connectivity check:
conn, err := net.DialTimeout("tcp", "api.dingtalk.com:443", 5*time.Second)
if err != nil { log.Fatal("cannot reach api.dingtalk.com: ", err) }
conn.Close()

Try / catch

if err != nil {
    if errors.Is(err, context.DeadlineExceeded) {
        log.Warn("dingtalk download API timed out")
    } else {
        log.Warn("dingtalk download API unreachable", "err", err)
    }
    return retryWithBackoff(2) // transient network issue
}

Prevention

When it happens

Trigger: Called from handleImageMessage, handleFileMessage, or downloadAudio; p.httpClient.Do(req) errored — e.g. no outbound network to api.dingtalk.com, proxy blocking, or context.WithTimeout(30s) deadline exceeded.

Common situations: Corporate firewall/proxy blocking api.dingtalk.com; DNS resolution failure; DingTalk API slow or unreachable; sustained network outage; extremely slow host causing the 30s timeout to fire.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/6465cef05f3a07b2. Report an issue: GitHub.