{"record":{"id":"5ed9ea802cb64b68","repo":"chenhg5/cc-connect","slug":"qq-http-s-failed-retcode-d-msg-s","errorCode":null,"errorMessage":"qq: HTTP %s failed (retcode=%d, msg=%s)","messagePattern":"qq: HTTP (.+?) failed \\(retcode=(.+?), msg=(.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/qq/qq.go","lineNumber":629,"sourceCode":"\t}\n\tdefer resp.Body.Close()\n\n\traw, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"qq: HTTP %s read body: %w\", action, err)\n\t}\n\n\tvar apiResp struct {\n\t\tStatus  string          `json:\"status\"`\n\t\tRetCode int             `json:\"retcode\"`\n\t\tData    json.RawMessage `json:\"data\"`\n\t\tMessage string          `json:\"message\"`\n\t}\n\tif json.Unmarshal(raw, &apiResp) != nil {\n\t\treturn nil, fmt.Errorf(\"qq: HTTP %s invalid response\", action)\n\t}\n\tif apiResp.RetCode != 0 {\n\t\treturn nil, fmt.Errorf(\"qq: HTTP %s failed (retcode=%d, msg=%s)\", action, apiResp.RetCode, apiResp.Message)\n\t}\n\tvar result map[string]any\n\t_ = json.Unmarshal(apiResp.Data, &result)\n\treturn result, nil\n}\n\n// ── Helpers ─────────────────────────────────────────────────────\n\ntype replyContext struct {\n\tmessageType string // \"private\" or \"group\"\n\tuserID      int64\n\tgroupID     int64\n\tmessageID   int32\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// qq:{userID}, qq:{groupID}:{userID} or qq:g:{groupID}\n\tparts := strings.SplitN(sessionKey, \":\", 3)","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/qq/qq.go#L611-L647","documentation":"callHTTPAPI returns this when the QQ OneBot HTTP API responded with valid JSON but a non-zero retcode, meaning the server itself rejected the action. retcode and the server's message are embedded so the specific API-level failure (bad parameter, auth failure, not found) is identifiable from the log.","triggerScenarios":"apiResp.RetCode != 0 in callHTTPAPI: e.g. retcode=1 (invalid params to get_group_member_info/send_msg), retcode=3 (no support), retcode=4 (bot not in the target group), retcode failed auth (retcode=403/token mismatch in some implementations).","commonSituations":"Bot removed from a group but session still cached; wrong message_id after message recall; sending private messages to users who blocked the bot; access_token mismatch; OneBot implementation version differences in retcode semantics.","solutions":["Read retcode and msg from the error to identify the specific API failure (e.g. 4 = bot not in group).","If auth-related, verify the access_token in config matches the OneBot server's token.","Re-fetch group/friend lists or refresh the session if the target no longer exists.","Check the OneBot implementation's docs for the returned retcode's meaning."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: verify bot membership before targeting a group\n// call get_group_info / get_group_member_info first and bail out on retcode != 0","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var apiErr *APIError // custom type holding RetCode/Msg parsed from the error string or wrapped value\n    if errors.As(err, &apiErr) && apiErr.RetCode == 4 {\n        // bot not in group: refresh group list or drop session\n    }\n    return err\n}","preventionTips":["Keep access_token in config in sync with the OneBot server token.","Refresh cached group/user targets when retcode indicates a missing entity.","Map retcodes to actionable messages in your own error handling."],"tags":["qq","api-error","onebot","retcode"],"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-14T00:17:10.932Z"}