{"record":{"id":"0172acb71988840f","repo":"JeffreySu/WeiXinMPSDK","slug":"errmsg","errorCode":null,"errorMessage":"{errmsg}","messagePattern":"\\{errmsg\\}","errorType":"exception","errorClass":"ErrorJsonResultException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/CommonApi.Menu.cs","lineNumber":161,"sourceCode":"                            //按钮，无下级菜单\n                            finalResult.menu.button.Add(GetSingleButtonFromJsonObject(fullButton));\n                        }\n                        else\n                        {\n                            //二级菜单\n                            var subButton = new SubButton(fullButton[\"name\"] as string);\n                            finalResult.menu.button.Add(subButton);\n                            foreach (var sb in fullButton[\"sub_button\"] as object[])\n                            {\n                                subButton.sub_button.Add(GetSingleButtonFromJsonObject(sb as Dictionary<string, object>));\n                            }\n                        }\n                    }\n                }\n                else if (fullResult != null && fullResult.ContainsKey(\"errmsg\"))\n                {\n                    //菜单不存在\n                    throw new ErrorJsonResultException(fullResult[\"errmsg\"] as string, null, null);\n                }\n            }\n            catch (ErrorJsonResultException ex)\n            {\n                finalResult = null;\n\n                //如果没有惨淡会返回错误代码：46003：menu no exist\n            }\n            catch (Exception ex)\n            {\n                //其他异常\n                finalResult = null;\n            }\n            return finalResult;\n        }\n\n\n        /// <summary>","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/CommonApi.Menu.cs#L143-L179","documentation":"GetMenuFromJson throws an ErrorJsonResultException whose message is the remote errmsg string when the query-menu JSON response contains an 'errmsg' key (e.g. the menu does not exist). Instead of a normal result, the library surfaces the WeChat Work API error so callers can distinguish 'no menu' from a parsed menu. Inside the method, this exception is also caught to set finalResult=null, but at the top level it propagates to the caller.","triggerScenarios":"Calling GetMenu (or GetMenuFromJson) for a corp app/agent whose custom menu was never created, or with an agentId that has no menu configured — WeChat Work returns {\"errmsg\":\"...\"} and the library throws with that errmsg as the message.","commonSituations":"Freshly created WeChat Work agent with no menu yet; querying the wrong agentId or secret; environment mismatch (test vs production app) where the target app never had a menu.","solutions":["Wrap the GetMenu call in try/catch for ErrorJsonResultException and treat it as 'menu not exists' (return null or an empty menu).","Create the menu first via CreateMenu/CreateMenuAsync for the correct agentId before querying it.","Verify agentId/corpId/secret correspond to the app that actually owns a menu.","Check the exception message for specific errcodes (e.g. menu not exist) to branch logic."],"exampleFix":"// before\nvar menu = CommonApi.GetMenu(token, agentId); // throws when no menu\n\n// after\nGetMenuResult menu = null;\ntry { menu = CommonApi.GetMenu(token, agentId); }\ncatch (ErrorJsonResultException ex)\n{\n    // menu does not exist yet\n}\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { menu = CommonApi.GetMenu(token, agentId); }\ncatch (ErrorJsonResultException ex)\n{\n    // treat as \"menu not exists\"; menu = null\n}","preventionTips":["Create the menu before ever querying it","Verify agentId belongs to the app whose secret you used","Distinguish environments (test/prod agents) in configuration","Log errmsg to identify whether it is a genuine no-menu case"],"tags":["wechat-work","menu","api-error","not-found"],"backgroundTag":"api-error-response","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}