chenhg5/cc-connect · error

weibo: read token response: %w

Error message

weibo: read token response: %w

What it means

Failure reading the token-endpoint response body (io.ReadAll): the server accepted the request and started responding, but the body stream was interrupted or the connection dropped mid-read. The status line may have been received; the JSON payload is incomplete or absent.

Source

Thrown at platform/weibo/weibo.go:173

		return p.token, nil
	}

	body := fmt.Sprintf(`{"app_id":"%s","app_secret":"%s"}`, p.appID, p.appSecret)
	req, err := http.NewRequest("POST", p.tokenEndpoint, strings.NewReader(body))
	if err != nil {
		return "", fmt.Errorf("weibo: build token request: %w", err)
	}
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return "", fmt.Errorf("weibo: token request: %w", err)
	}
	defer resp.Body.Close()

	raw, err := io.ReadAll(resp.Body)
	if err != nil {
		return "", fmt.Errorf("weibo: read token response: %w", err)
	}

	if resp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("weibo: token HTTP %d: %s", resp.StatusCode, string(raw))
	}

	var tr tokenResponse
	if err := json.Unmarshal(raw, &tr); err != nil {
		return "", fmt.Errorf("weibo: parse token response: %w", err)
	}
	if tr.Data.Token == "" {
		return "", fmt.Errorf("weibo: empty token in response: %s", string(raw))
	}

	p.token = tr.Data.Token
	p.tokenExpiry = time.Now().Add(time.Duration(tr.Data.ExpireIn) * time.Second)
	if len(tr.Data.UID) > 0 {
		p.uid = strings.Trim(string(tr.Data.UID), `"`)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the refresh — interrupted body reads are typically transient network drops
  2. If persistent, check for proxies or middleware that truncate long-lived response streams
  3. Log how many bytes were read before the failure to gauge truncation point
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at platform/weibo/weibo.go:173 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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