chenhg5/cc-connect · error

yuanbao: request failed: %w

Error message

yuanbao: request failed: %w

What it means

The HTTP client's Do(req) call inside yuanbao's fetchToken returned a transport-level error (DNS failure, connection refused, TLS error, timeout). The error is wrapped as lastErr and the retry loop continues to the next attempt; after all retries the last error is returned. It means the sign-token API endpoint could not be reached at all.

Source

Thrown at platform/yuanbao/sign.go:154

		}
		body, _ := json.Marshal(payload)

		req, err := http.NewRequest("POST", urlStr, strings.NewReader(string(body)))
		if err != nil {
			lastErr = fmt.Errorf("yuanbao: create request: %w", err)
			continue
		}
		req.Header.Set("Content-Type", "application/json")
		req.Header.Set("X-AppVersion", "cc-connect-yuanbao/1.0.0")
		req.Header.Set("X-Instance-Id", fmt.Sprintf("%d", instanceID))
		req.Header.Set("X-Bot-Version", "cc-connect-yuanbao/1.0.0")
		if routeEnv != "" {
			req.Header.Set("X-Route-Env", routeEnv)
		}

		resp, err := client.Do(req)
		if err != nil {
			lastErr = fmt.Errorf("yuanbao: request failed: %w", err)
			continue
		}
		respBody, _ := io.ReadAll(resp.Body)
		_ = resp.Body.Close()
		if resp.StatusCode != http.StatusOK {
			lastErr = fmt.Errorf("yuanbao: sign token API returned %d: %s", resp.StatusCode, string(respBody))
			continue
		}

		var result struct {
			Code int `json:"code"`
			Data *struct {
				Token    string `json:"token"`
				BotID    string `json:"bot_id"`
				Duration int    `json:"duration"`
				Product  string `json:"product"`
				Source   string `json:"source"`
			} `json:"data"`

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify network reachability: `curl -v https://<api_domain>` from the same host to see DNS/TLS/connection errors.
  2. Check the api_domain setting in config.toml for typos or a stale/renamed endpoint.
  3. Check proxy environment variables (HTTP_PROXY/HTTPS_PROXY/NO_PROXY) if the host requires a proxy.
  4. Retry later if the endpoint is temporarily down — fetchToken already retries up to maxRetries internally.

Example fix

// before (verifying config)
api_domain = "https://yuanbao-wrong-host.example.com"
// after
api_domain = "https://yuanbao.example.com"
Defensive patterns

Strategy: retry

Validate before calling

conn, err := net.DialTimeout("tcp", host+":443", 5*time.Second)
if err != nil { return fmt.Errorf("sign-token host unreachable: %w", err) }
conn.Close()

Try / catch

if err := fetchToken(...); err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) { /* schedule retry with backoff */ }
    slog.Error("token fetch failed", "err", err)
}

Prevention

When it happens

Trigger: client.Do(req) returns err during any fetchToken attempt — called from getToken at session start or from VerifyCredentials during `cc-connect yuanbao setup`.

Common situations: api_domain pointing to a host that is down or wrong (typo in domain), corporate proxy/firewall blocking outbound HTTPS, DNS not resolving the yuanbao endpoint, no internet access from the daemon host.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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