{"record":{"id":"1b5a10dcaae24a05","repo":"AlexxIT/go2rtc","slug":"tokenresp-msg","errorCode":null,"errorMessage":"${tokenResp.Msg}","messagePattern":"\\$\\{tokenResp\\.Msg\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/tuya/smart_api.go","lineNumber":432,"sourceCode":"\n\ttokenReq := LoginTokenRequest{\n\t\tCountryCode: c.countryCode,\n\t\tUsername:    c.email,\n\t\tIsUid:       false,\n\t}\n\n\tbody, err := c.request(\"POST\", tokenUrl, tokenReq)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar tokenResp LoginTokenResponse\n\tif err := json.Unmarshal(body, &tokenResp); err != nil {\n\t\treturn err\n\t}\n\n\tif !tokenResp.Success {\n\t\treturn errors.New(tokenResp.Msg)\n\t}\n\n\tencryptedPassword, err := EncryptPassword(c.password, tokenResp.Result.PbKey)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to encrypt password: %v\", err)\n\t}\n\tvar loginUrl string\n\n\tloginReq := PasswordLoginRequest{\n\t\tCountryCode: c.countryCode,\n\t\tPasswd:      encryptedPassword,\n\t\tToken:       tokenResp.Result.Token,\n\t\tIfEncrypt:   1,\n\t\tOptions:     `{\"group\":1}`,\n\t}\n\n\tif IsEmailAddress(c.email) {\n\t\tloginUrl = fmt.Sprintf(\"https://%s/api/private/email/login\", c.baseUrl)","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/smart_api.go#L414-L450","documentation":"initToken returns this error when the Tuya login-token API responds with Success=false; tokenResp.Msg is passed to errors.New directly. The token bootstrap step failed, so no session can be established and all subsequent API calls will also fail. The server's message is surfaced verbatim.","triggerScenarios":"Calling initToken (or any higher-level call that triggers it) when the login-token endpoint returns Success=false — e.g. wrong username/password, disabled account, or cloud rejection.","commonSituations":"Changed Tuya account password; account locked or captcha required; wrong region endpoint; network path to a stale endpoint; Tuya SDK version mismatch.","solutions":["Read Msg: authentication failures require credential fixes; server errors allow a retry.","Verify username/password and region configuration used to construct TuyaSmartApiClient.","Re-run the full login flow after fixing credentials.","Add bounded retry with backoff for transient cloud errors only.","Check for captcha/2FA requirements indicated in the message."],"exampleFix":"// before\nc := tuya.NewClient(user, pass, region)\nif err := c.initToken(); err != nil {\n    return err\n}\n// after\nif err := c.initToken(); err != nil {\n    return fmt.Errorf(\"tuya token init for %s@%s: %w\", user, region, err)\n}","handlingStrategy":"try-catch","validationCode":"if username == \"\" || password == \"\" || region == \"\" { return errors.New(\"missing tuya credentials/region\") } // before initToken","typeGuard":null,"tryCatchPattern":"if err := c.initToken(); err != nil {\n    if strings.Contains(err.Error(), \"password\") || strings.Contains(err.Error(), \"account\") {\n        return ErrBadCredentials // do not retry\n    }\n    return fmt.Errorf(\"init token: %w\", err) // transient: retry with backoff\n}","preventionTips":["Verify credentials and region before constructing the client","Never retry on credential-type messages","Handle captcha/2FA paths","Fetch a fresh token key before encrypting passwords"],"tags":["api","tuya","authentication"],"backgroundTag":"authentication-required","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}