chenhg5/cc-connect · error

decode response: %w

Error message

decode response: %w

What it means

validateAppCredentialsAgainstBase issues a POST to the tenant_access_token endpoint and unmarshals the JSON body into tenantTokenResponse. This error wraps any json.Unmarshal failure, meaning the remote answered but not with the expected JSON shape.

Source

Thrown at cmd/cc-connect/feishu.go:523

		return false, err
	}
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 10 * time.Second}
	resp, err := client.Do(req)
	if err != nil {
		return false, err
	}
	defer resp.Body.Close()

	data, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
	if err != nil {
		return false, err
	}

	var parsed tenantTokenResponse
	if err := json.Unmarshal(data, &parsed); err != nil {
		return false, fmt.Errorf("decode response: %w", err)
	}
	if parsed.Code == 0 && parsed.TenantAccessToken != "" {
		return true, nil
	}
	if parsed.Msg != "" {
		return false, fmt.Errorf("code=%d msg=%s", parsed.Code, parsed.Msg)
	}
	return false, nil
}

func runRegistrationFlow(opts registrationFlowOptions) (*registrationFlowResult, error) {
	if opts.TimeoutSeconds <= 0 {
		opts.TimeoutSeconds = 600
	}
	client := &registrationClient{
		baseURL: accountsFeishuBaseURL,
		http:    &http.Client{Timeout: 15 * time.Second},
		debug:   opts.Debug,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify the base URL is the real Feishu/Lark auth endpoint (open.feishu.cn / open.larksuite.com).
  2. Disable or bypass intercepting proxies/VPNs for the request.
  3. Re-run later if Feishu is having an incident; retry may yield a well-formed response.
  4. Inspect the raw response with --debug to see what body was actually received.
Defensive patterns

Strategy: retry

Validate before calling

resp, err := http.Post(url, "application/json", body); if err == nil { var probe map[string]any; if jerr := json.NewDecoder(resp.Body).Decode(&probe); jerr != nil { return fmt.Errorf("endpoint not returning JSON: %w", jerr) } }

Try / catch

if _, err := validateAppCredentials(...); err != nil && strings.Contains(err.Error(), "decode response:") { log.Printf("non-JSON response from auth endpoint: %v; check proxy/base URL", err) }

Prevention

When it happens

Trigger: The base URL points at a non-Feishu service (proxy/captive portal returning HTML), the endpoint returns an HTML error page, or a malformed/empty JSON body arrives despite HTTP success.

Common situations: Corporate proxies intercepting requests; wrong base URL override; network appliances returning login pages; Feishu returning an unexpected content type during incidents.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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