{"record":{"id":"420237d67e7f5fb0","repo":"JeffreySu/WeiXinMPSDK","slug":"thirdpartymessagehandler-executeasync","errorCode":null,"errorMessage":"ThirdPartyMessageHandler中ExecuteAsync()过程发生错误：","messagePattern":"ThirdPartyMessageHandler中ExecuteAsync\\(\\)过程发生错误：","errorType":"exception","errorClass":"MessageHandlerException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Open/Senparc.Weixin.Open/MessageHandlers/ThirdPartyMessageHandlerAsync.cs","lineNumber":154,"sourceCode":"                        {\n                            var requestMessage = RequestMessage as RequestMessageOrderPathApplyResultNotify;\n                            ResponseMessageText = await OnOrderPathApplyResultNotifyRequestAsync(requestMessage, cancellationToken);\n                        }\n                        break;\n                    case RequestInfoType.order_path_audit_result_notify:\n                        {\n                            var requestMessage = RequestMessage as RequestMessageOrderPathAuditResultNotify;\n                            ResponseMessageText = await OnOrderPathAuditResultNotifyRequestAsync(requestMessage, cancellationToken);\n                        }\n                        break;\n                    default:\n                        throw new UnknownRequestMsgTypeException(\"未知的InfoType请求类型\", null);\n                }\n\n            }\n            catch (Exception ex)\n            {\n                throw new MessageHandlerException(\"ThirdPartyMessageHandler中ExecuteAsync()过程发生错误：\" + ex.Message, ex);\n            }\n            finally\n            {\n                await OnExecutedAsync(cancellationToken);\n            }\n        }\n\n        public virtual Task OnExecutingAsync(CancellationToken cancellationToken)\n        {\n            OnExecuting();\n            return Task.CompletedTask;\n        }\n\n        public virtual Task OnExecutedAsync(CancellationToken cancellationToken)\n        {\n            OnExecuted();\n            return Task.CompletedTask;\n        }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Open/Senparc.Weixin.Open/MessageHandlers/ThirdPartyMessageHandlerAsync.cs#L136-L172","documentation":"ExecuteAsync wraps all message dispatch in a try-catch and rethrows any exception as MessageHandlerException with the message 'ThirdPartyMessageHandler中ExecuteAsync()过程发生错误：' + the inner message. This is a wrapper error: the root cause (e.g. error [74], a handler callback throwing, XML parsing) is in the InnerException.","triggerScenarios":"Any exception inside ThirdPartyMessageHandlerAsync.ExecuteAsync — unknown InfoType, null request message, user-registered On*Async callbacks throwing, or serialization failures during third-party message processing.","commonSituations":"Debugging why a WeChat component push returns an error; the surfaced message alone ('...发生错误：') is unhelpful because the true cause is nested inside InnerException.","solutions":["Inspect ex.InnerException — the real error (e.g. UnknownRequestMsgTypeException with the InfoType) is there.","Fix the root cause: upgrade the SDK for unknown InfoTypes, or fix the throwing On*Async callback.","Log full exception with inner chain in your OnExecuted/error logging instead of only ex.Message."],"exampleFix":"// before\ncatch (MessageHandlerException ex)\n{\n    logger.LogError(ex.Message);\n}\n// after\ncatch (MessageHandlerException ex)\n{\n    logger.LogError(ex, \"ThirdParty handler failed: {Inner}\", ex.InnerException?.ToString());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await handler.ExecuteAsync(ct); }\ncatch (MessageHandlerException ex)\n{ logger.LogError(ex.InnerException ?? ex, \"Third-party handler root cause: {Msg}\", ex.InnerException?.Message); }","preventionTips":["Always log InnerException for MessageHandlerException — the wrapper message is not actionable.","Wrap individual On*Async callbacks with their own error handling so failures are localized.","Test the handler with recorded WeChat push payloads in CI."],"tags":["weixin-open","message-handler","wrapper-exception","inner-exception"],"backgroundTag":"api-request-failed","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"}