chenhg5/cc-connect · error

HTTP GET %s: %w

Error message

HTTP GET %s: %w

What it means

`fetchPresetsFromURL` wraps any transport-level failure of `http.Client.Get` — DNS failure, connection refused, TLS error, or timeout — as `HTTP GET <url>: <cause>`. It indicates the request never completed at the HTTP layer, so no status code exists yet.

Source

Thrown at core/provider_presets.go:140

	if err != nil {
		if c.data != nil {
			slog.Warn("all presets sources failed, using stale cache", "error", err)
			return c.data, nil
		}
		return nil, fmt.Errorf("fetch presets: %w", err)
	}

	c.data = result
	c.fetchedAt = time.Now()
	return c.data, nil
}

func fetchPresetsFromURL(url string, timeout time.Duration) (*ProviderPresetsResponse, error) {
	slog.Debug("fetching provider presets", "url", url)
	client := &http.Client{Timeout: timeout}
	resp, err := client.Get(url)
	if err != nil {
		return nil, fmt.Errorf("HTTP GET %s: %w", url, err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("HTTP GET %s: status %d", url, resp.StatusCode)
	}

	body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
	if err != nil {
		return nil, fmt.Errorf("read body from %s: %w", url, err)
	}

	var result ProviderPresetsResponse
	if err := json.Unmarshal(body, &result); err != nil {
		return nil, fmt.Errorf("parse JSON from %s: %w", url, err)
	}
	return &result, nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Test the exact URL manually: `curl -v <url>` and fix DNS/proxy/certificate issues it reveals.
  2. Check the configured presets URL for typos (scheme, host, port).
  3. If behind a proxy, set HTTPS_PROXY / trust the corporate root CA.
  4. If timeouts recur, increase the fetch timeout parameter or move to a closer mirror of the presets source.

Example fix

// before
resp, err := client.Get(url)
if err != nil { return nil, fmt.Errorf("HTTP GET %s: %w", url, err) }

// after (caller-side retry with backoff)
var resp *http.Response
var err error
for i := 0; i < 3; i++ {
    resp, err = client.Get(url)
    if err == nil { break }
    time.Sleep(time.Duration(1<<i) * time.Second)
}
Defensive patterns

Strategy: retry

Validate before calling

u, err := url.Parse(url)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return errors.New("presets URL must be absolute http(s)") }

Try / catch

var resp *http.Response
var err error
for attempt := 0; attempt < 3; attempt++ {
    resp, err = client.Get(url)
    if err == nil { break }
    time.Sleep(time.Duration(1<<attempt) * time.Second)
}

Prevention

When it happens

Trigger: Calling fetchPresetsFromURL (via the presets cache fetch) where `client.Get(url)` returns a non-nil error: unreachable host, refused connection, expired TLS cert, or the configured per-request timeout elapsing.

Common situations: Typo in the presets URL scheme/host; firewall or VPN blocking outbound HTTPS; corporate MITM proxy with an untrusted CA; slow network hitting the client Timeout.

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/f955880f7669cd72. Report an issue: GitHub.