{"record":{"id":"f691bf13cb5a299a","repo":"siyuan-note/siyuan","slug":"conf-language-31","errorCode":null,"errorMessage":"Conf.Language(31)","messagePattern":"Conf\\.Language\\(31\\)","errorType":"exception","errorClass":null,"httpStatus":401,"severity":"error","filePath":"kernel/model/cloud_service.go","lineNumber":77,"sourceCode":"\t\t\"content\": msg,\n\t})\n\tpayload[\"messages\"] = messages\n\n\trequestResult := gulu.Ret.NewResult()\n\trequest := httpclient.NewCloudRequest30s()\n\tresp, err := request.\n\t\tSetSuccessResult(requestResult).\n\t\tSetCookies(&http.Cookie{Name: \"symphony\", Value: user.UserToken}).\n\t\tSetBody(payload).\n\t\tPost(util.GetCloudServer() + \"/apis/siyuan/ai/chatGPT\")\n\tif err != nil {\n\t\tlogging.LogErrorf(\"chat gpt failed: %s\", err)\n\t\terr = ErrFailedToConnectCloudServer\n\t\treturn\n\t}\n\tif http.StatusUnauthorized == resp.StatusCode {\n\t\tinvalidUser()\n\t\treturn \"\", true, errors.New(Conf.Language(31))\n\t}\n\tif http.StatusOK != resp.StatusCode {\n\t\treturn \"\", true, ErrFailedToConnectCloudServer\n\t}\n\tif 0 != requestResult.Code {\n\t\terr = errors.New(requestResult.Msg)\n\t\tstop = true\n\t\treturn\n\t}\n\n\tdata := requestResult.Data.(map[string]any)\n\tchoices := data[\"choices\"].([]any)\n\tif 1 > len(choices) {\n\t\tstop = true\n\t\treturn\n\t}\n\tchoice := choices[0].(map[string]any)\n\tmessage := choice[\"message\"].(map[string]any)","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/cloud_service.go#L59-L95","documentation":"When the ChatGPT cloud endpoint responds with HTTP 401 Unauthorized, CloudChatGPT calls invalidUser() to clear the stale account and returns errors.New(Conf.Language(31)) — a localized 'please log in to the cloud server' message (i18n key 31) surfaced to the user as the error text.","triggerScenarios":"Calling the AI chat feature while the stored cloud user token is expired, revoked, or otherwise rejected by the cloud server, causing a 401 response.","commonSituations":"Cloud session expired after long inactivity; password changed on another device invalidating the token; server-side token revocation; user never logged in but a stale user record exists in config.","solutions":["Re-login to the cloud account (Settings - Account - Log in) to obtain a fresh token","Log out and back in to clear the invalidated user record (invalidUser() already cleared it in the kernel)","If no cloud account is intended, disable AI features that require cloud auth"],"exampleFix":"// caller: detect auth failure and prompt re-login\n_, _, err := model.CloudChatGPT(msg, ctx)\nif err != nil && err.Error() == Conf.Language(31) {\n    // token rejected: open the account panel for re-login\n    openAccountPanel()\n}","handlingStrategy":"try-catch","validationCode":"// caller: only offer AI chat when a cloud user is present\nif (!window.siyuan.user) { promptLogin(); return; }","typeGuard":null,"tryCatchPattern":"_, _, err := model.CloudChatGPT(msg, ctx)\nif err != nil && err.Error() == Conf.Language(31) {\n    invalidUserFlow() // re-login prompt\n}","preventionTips":["Check for a logged-in cloud user before offering AI features","Handle token expiry proactively by refreshing the session periodically","After any 401-driven invalidation, clear the UI's cached user state"],"tags":["authentication","cloud","token-expired"],"backgroundTag":"authentication-required","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}