{"record":{"id":"4a8f0336d3d0359e","repo":"chenhg5/cc-connect","slug":"s-s-failed-code-d-msg-s","errorCode":null,"errorMessage":"%s: %s failed code=%d msg=%s","messagePattern":"(.+?): (.+?) failed code=(.+?) msg=(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":4081,"sourceCode":"}\n\nfunc (p *Platform) createMessage(ctx context.Context, chatID, msgType, content, op string) error {\n\treq := larkim.NewCreateMessageReqBuilder().\n\t\tReceiveIdType(larkim.ReceiveIdTypeChatId).\n\t\tBody(larkim.NewCreateMessageReqBodyBuilder().\n\t\t\tReceiveId(chatID).\n\t\t\tMsgType(msgType).\n\t\t\tContent(content).\n\t\t\tBuild()).\n\t\tBuild()\n\treturn p.withTransientRetry(ctx, op, func() error {\n\t\treturn p.withFreshTenantAccessTokenRetry(ctx, op, func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {\n\t\t\tresp, err := client.Im.Message.Create(ctx, req, options...)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s: %s api call: %w\", p.tag(), op, err)\n\t\t\t}\n\t\t\tif !resp.Success() {\n\t\t\t\treturn fmt.Errorf(\"%s: %s failed code=%d msg=%s\", p.tag(), op, resp.Code, resp.Msg)\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t})\n}\n\nfunc (p *Platform) withFreshTenantAccessTokenRetry(ctx context.Context, operation string, fn feishuRequestFunc) error {\n\terr := fn(p.client)\n\tif !isTenantAccessTokenInvalid(err) {\n\t\treturn err\n\t}\n\n\tfreshToken, refreshErr := p.fetchFreshTenantAccessToken(ctx)\n\tif refreshErr != nil {\n\t\treturn fmt.Errorf(\"%s: %s failed after token refresh attempt: %w (original error: %v)\", p.tag(), operation, refreshErr, err)\n\t}\n\n\tslog.Warn(p.tag()+\": retrying request with fresh tenant access token\", \"operation\", operation)","sourceCodeStart":4063,"sourceCodeEnd":4099,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L4063-L4099","documentation":"The Feishu Create-message API returned a business error: the response indicates !resp.Success() and the Feishu code/msg are embedded in the message. Feishu explicitly rejected sending the message (bad receive_id, permission, invalid msg_type/content, or rate limit).","triggerScenarios":"client.Im.Message.Create succeeds at HTTP level but body code != 0 — invalid chat_id, bot not in the chat, malformed JSON content for the msg_type, missing im:message scope, or QPS limit exceeded.","commonSituations":"Sending to a chat the bot was removed from, passing non-JSON-escaped text as content, wrong msgType string (e.g. 'text' vs 'interactive'), or burst traffic triggering rate limiting.","solutions":["Cross-reference the embedded code with Feishu's error-code table.","Validate that msgType/content JSON is well-formed (use json.Marshal for the content payload).","Confirm the bot is still a member of the target chat and holds im:message scopes.","Apply backoff if the code indicates rate limiting."],"exampleFix":"// before\ncontent := fmt.Sprintf(\"{\\\"text\\\":\\\"%s\\\"}\", text)\n// after\ncontentBytes, _ := json.Marshal(map[string]string{\"text\": text})\ncontent := string(contentBytes)","handlingStrategy":"validation","validationCode":"contentBytes, err := json.Marshal(map[string]string{\"text\": text})\nif err != nil { return err }\nif chatID == \"\" { return errors.New(\"missing chat_id\") }","typeGuard":null,"tryCatchPattern":"err := p.sendMessage(ctx, chatID, msgType, content)\nif err != nil {\n\tvar code int\n\tif extractFeishuCode(err, &code) && code == 99991400 {\n\t\ttime.Sleep(backoff)\n\t\treturn p.sendMessage(ctx, chatID, msgType, content)\n\t}\n\treturn err\n}","preventionTips":["Always build content via json.Marshal, never string concatenation.","Use core message-type constants instead of raw strings.","Throttle outbound sends to stay under Feishu QPS limits.","Verify bot chat membership after membership-change webhooks."],"tags":["feishu","lark","api","send","error-code"],"backgroundTag":"api-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}