chenhg5/cc-connect · error

weibo: build token request: %w

Error message

weibo: build token request: %w

What it means

Wrap of http.NewRequest while building the token-refresh POST: request construction failed, which in practice means the configured token_endpoint is not a parseable URL (bad scheme, control characters, or empty after config typo). The request is never sent, so this is a local configuration error, not a network one.

Source

Thrown at platform/weibo/weibo.go:161

		ExpireIn int64           `json:"expire_in"` // seconds
		UID      json.RawMessage `json:"uid"`
	} `json:"data"`
	Error     string `json:"error"`
	ErrorCode int    `json:"error_code"`
}

func (p *Platform) refreshToken() (string, error) {
	p.tokenMu.Lock()
	defer p.tokenMu.Unlock()

	if p.token != "" && time.Now().Before(p.tokenExpiry.Add(-tokenRenewBuf)) {
		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))
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Validate token_endpoint in config.toml — it must be a full URL including scheme
  2. Default the endpoint when unset (the code already falls back to defaultTokenEndpoint)
  3. Fail fast with a clear config-error message at startup
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at platform/weibo/weibo.go:161 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/9fbbe1b8c4707cfe. Report an issue: GitHub.