chenhg5/cc-connect · error

http %d: %s

Error message

http %d: %s

What it means

weixinHTTPGet is the shared HTTP GET helper for the WeChat ilink setup flow. When the server responds with any status code other than 200 OK, it discards the body as a success payload and returns this error embedding the numeric status and a truncated (256-char) response body so the underlying API failure reason is visible to the caller.

Source

Thrown at cmd/cc-connect/weixin.go:411

	client := &http.Client{Timeout: weixinQRPollTimeout + 5*time.Second}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
	if err != nil {
		return nil, err
	}
	if debug {
		snippet := string(body)
		if len(snippet) > 200 {
			snippet = snippet[:200]
		}
		fmt.Fprintf(os.Stderr, "[debug] GET %s -> %d %s\n", fullURL, resp.StatusCode, strings.TrimSpace(snippet))
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("http %d: %s", resp.StatusCode, weixinTruncateBody(body, 256))
	}
	return body, nil
}

func weixinTruncateBody(b []byte, max int) string {
	s := string(b)
	if len(s) <= max {
		return s
	}
	return s[:max] + "…"
}

func weixinFetchBotQRCode(ctx context.Context, apiBase, botType, routeTag string, debug bool) (*weixinBotQRResponse, error) {
	base := strings.TrimRight(apiBase, "/") + "/"
	u, err := url.Parse(base)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the embedded status code and body snippet to identify the server-side reason
  2. Verify the weixin api_base URL in your config is correct and reachable (curl it directly)
  3. Retry later if the status is 429 or 5xx — the service may be rate limiting or down
  4. Check proxy/firewall settings if the body shows a gateway or proxy error page

Example fix

// before (blind retry on any URL)
raw, err := weixinHTTPGet(ctx, "https://wrong-host/ilink/bot/get_bot_qrcode", ...)
// after (verify endpoint first)
if u.Host != "correct-ilink-host" { return nil, fmt.Errorf("weixin: unexpected api base %s", u.Host) }
raw, err := weixinHTTPGet(ctx, u.String(), ...)
Defensive patterns

Strategy: try-catch

Validate before calling

resp, err := http.Get(apiBase + "/ilink/bot/get_bot_qrcode?bot_type=...")
if err != nil || resp.StatusCode != http.StatusOK {
    return fmt.Errorf("weixin api unreachable: status=%v err=%v", statusOf(resp), err)
}

Try / catch

raw, err := weixinHTTPGet(ctx, u, routeTag, debug)
var httpErr *weixinHTTPError
if errors.As(err, &httpErr) {
    switch {
    case httpErr.Status == 429 || httpErr.Status >= 500:
        // backoff and retry
    default:
        // fail fast with body snippet
    }
}

Prevention

When it happens

Trigger: Any weixin setup HTTP call (e.g. weixinFetchBotQRCode fetching get_bot_qrcode) receiving a non-200 status such as 401 (invalid route/token), 403, 429 (rate limit), or 5xx from the ilink API endpoint.

Common situations: Wrong or stale API base URL configured; corporate proxy or firewall returning an error page; ilink service outage or rate limiting; region/route tag mismatch causing server rejection.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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