chenhg5/cc-connect · error

dingtalk: emotion request: %w

Error message

dingtalk: emotion request: %w

What it means

This error is returned by sendEmotion when the HTTP client fails to execute the POST to DingTalk's emotion API — i.e. the request never got a response. The wrapped err from p.httpClient.Do carries the real cause: DNS resolution failure, connection refused/reset, TLS error, or the client's 30-second timeout firing. It means the emotion (typing indicator / reaction / recall) could not be delivered due to a transport-level problem, not an API rejection.

Source

Thrown at platform/dingtalk/dingtalk.go:961

			Text:         emoji,
			BackgroundID: customTextEmotionBackground,
		},
	}
	body, err := json.Marshal(requestBody)
	if err != nil {
		return fmt.Errorf("dingtalk: marshal emotion request: %w", err)
	}

	req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.dingtalk.com"+path, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("dingtalk: create emotion 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("dingtalk: emotion request: %w", err)
	}
	defer func() { _ = resp.Body.Close() }()

	respBody, _ := io.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("dingtalk: emotion returned status %d: %s", resp.StatusCode, string(respBody))
	}
	if len(respBody) == 0 {
		return nil
	}
	var result struct {
		Success *bool `json:"success"`
	}
	if err := json.Unmarshal(respBody, &result); err == nil && result.Success != nil && !*result.Success {
		return fmt.Errorf("dingtalk: emotion returned success=false")
	}
	return nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check outbound connectivity from the host: curl -v https://api.dingtalk.com/v1.0/robot/emotion/reply
  2. Verify DNS resolves api.dingtalk.com on the host
  3. Check proxy/firewall rules; set HTTPS_PROXY if the host requires a proxy
  4. If timeouts recur, investigate network latency between the host and api.dingtalk.com (client timeout is fixed at 30s)
  5. Simply retry — transient connection resets are common

Example fix

// environment check
// before: connection silently fails behind corporate proxy
// after: export proxy so Go's http client uses it
export HTTPS_PROXY=http://proxy.corp.local:8080
Defensive patterns

Strategy: retry

Validate before calling

// Go: check outbound reachability before relying on emotion features
resp, err := http.Head("https://api.dingtalk.com")
if err != nil {
    return fmt.Errorf("dingtalk unreachable: %w", err)
}
resp.Body.Close()

Try / catch

err := p.StartTyping(ctx, rctx)
for i := 0; i < 3 && err != nil; i++ {
    if errors.Is(err, context.DeadlineExceeded) || isNetErr(err) {
        time.Sleep(time.Duration(1<<i) * time.Second)
        err = p.StartTyping(ctx, rctx)
        continue
    }
    break
}

Prevention

When it happens

Trigger: p.httpClient.Do(req) returns an error during sendEmotion — network outage, DNS failure for api.dingtalk.com, connection reset by a proxy/firewall, TLS handshake failure, or the 30s client timeout elapsing on a hung connection.

Common situations: Server hosting cc-connect lost internet or has a firewall blocking api.dingtalk.com; corporate proxy requiring configuration; slow network causing the 30-second timeout; transient DingTalk-side connection resets.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


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