chenhg5/cc-connect · error

weixin: getConfig json: %w

Error message

weixin: getConfig json: %w

What it means

getConfig calls ilink/bot/getconfig to fetch per-user context configuration (used to obtain the typing ticket) and decodes the body into getConfigResp. This error wraps a json.Unmarshal failure: the reply is not valid JSON or no longer matches the struct.

Source

Thrown at platform/weixin/client.go:230

}

func (c *apiClient) getConfig(ctx context.Context, userID, contextToken string) (*getConfigResp, error) {
	req := getConfigReq{
		UserID:       userID,
		ContextToken: contextToken,
		BaseInfo:     baseInfo{ChannelVersion: channelVersion},
	}
	payload, err := json.Marshal(req)
	if err != nil {
		return nil, err
	}
	raw, err := c.post(ctx, "ilink/bot/getconfig", payload, 0, "getConfig")
	if err != nil {
		return nil, err
	}
	var out getConfigResp
	if err := json.Unmarshal(raw, &out); err != nil {
		return nil, fmt.Errorf("weixin: getConfig json: %w", err)
	}
	if out.Ret != 0 || out.Errcode != 0 {
		return nil, fmt.Errorf("weixin: getConfig ret=%d errcode=%d errmsg=%s", out.Ret, out.Errcode, out.Errmsg)
	}
	return &out, nil
}

func (c *apiClient) sendTyping(ctx context.Context, userID, typingTicket string, status int) error {
	req := sendTypingReq{
		IlinkUserID:  userID,
		TypingTicket: typingTicket,
		Status:       status,
		BaseInfo:     baseInfo{ChannelVersion: channelVersion},
	}
	payload, err := json.Marshal(req)
	if err != nil {
		return err
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Capture the raw body for inspection (add truncateForLog to the error)
  2. Refresh the bot session/ticket and retry
  3. Update getConfigResp to the current API schema
  4. Eliminate intermediaries that replace JSON with HTML
Defensive patterns

Strategy: try-catch

Validate before calling

if userID == "" || contextToken == "" { return errors.New("weixin: getConfig requires userID and contextToken") }

Try / catch

cfg, err := getConfig(ctx, userID, token)
if err != nil {
	if strings.Contains(err.Error(), "getConfig json") { refreshSession(); return retry() }
	return err
}

Prevention

When it happens

Trigger: The getconfig endpoint returns non-JSON (HTML error page, empty/gateway body) or an iLink schema change breaks decoding into getConfigResp.

Common situations: Expired bot session causing an error page; proxy/WAF rewriting the body; WeChat iLink API protocol update.

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