{"record":{"id":"b1147c030cdfa73c","repo":"chenhg5/cc-connect","slug":"code-d-msg-s","errorCode":null,"errorMessage":"code=%d msg=%s","messagePattern":"code=(.+?) msg=(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/feishu.go","lineNumber":529,"sourceCode":"\tif err != nil {\n\t\treturn false, err\n\t}\n\tdefer resp.Body.Close()\n\n\tdata, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\tvar parsed tenantTokenResponse\n\tif err := json.Unmarshal(data, &parsed); err != nil {\n\t\treturn false, fmt.Errorf(\"decode response: %w\", err)\n\t}\n\tif parsed.Code == 0 && parsed.TenantAccessToken != \"\" {\n\t\treturn true, nil\n\t}\n\tif parsed.Msg != \"\" {\n\t\treturn false, fmt.Errorf(\"code=%d msg=%s\", parsed.Code, parsed.Msg)\n\t}\n\treturn false, nil\n}\n\nfunc runRegistrationFlow(opts registrationFlowOptions) (*registrationFlowResult, error) {\n\tif opts.TimeoutSeconds <= 0 {\n\t\topts.TimeoutSeconds = 600\n\t}\n\tclient := &registrationClient{\n\t\tbaseURL: accountsFeishuBaseURL,\n\t\thttp:    &http.Client{Timeout: 15 * time.Second},\n\t\tdebug:   opts.Debug,\n\t}\n\n\tvar initRes registrationInitResponse\n\tif err := client.registrationCall(\"init\", nil, &initRes); err != nil {\n\t\treturn nil, fmt.Errorf(\"init failed: %w\", err)\n\t}","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/feishu.go#L511-L547","documentation":"After decoding the tenant_token response, if code != 0 or the token is empty, the API's own error is surfaced as `code=<code> msg=<msg>` when msg is non-empty. This is the Feishu/Lark API's own rejection of the credential, passed through verbatim.","triggerScenarios":"The tenant_access_token endpoint responds with a non-zero business code (e.g. invalid app_id, invalid app_secret, app not enabled) together with a human-readable msg.","commonSituations":"Wrong secret after rotation; using a Lark app against the Feishu endpoint; app disabled or deleted; insufficient app permissions for token issuance.","solutions":["Look up the numeric code in Feishu/Lark open-platform docs and fix per the msg.","Re-copy app_id/app_secret from the console; secrets are shown only once at creation.","Confirm the app is enabled and belongs to the tenant matching the base URL (feishu vs lark).","If the secret was rotated, use the new value in --app."],"exampleFix":"// before\ncc-connect feishu setup --app cli_wrongid:old_secret\n// after\ncc-connect feishu setup --app \"cli_a1b2c3:new_secret\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"var apiErr struct{ Code int `json:\"code\"`; Msg string `json:\"msg\"` }\nif _, err := validateAppCredentials(...); err != nil {\n    if code, msg, ok := parseCodeMsg(err.Error()); ok { // matches code=%d msg=%s\n        handleFeishuAPIError(code, msg) // look up code in Feishu docs\n    }\n}","preventionTips":["Re-copy credentials from the console after any secret rotation.","Confirm app region and tenant match the base URL used.","Keep the app enabled with token-issuing permissions granted."],"tags":["feishu","authentication","api-error","credentials"],"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"}