{"record":{"id":"a3ca572b00231649","repo":"babalae/better-genshin-impact","slug":"error-sending-onebot-message-ex-message","errorCode":null,"errorMessage":"Error sending OneBot message: {ex.Message}","messagePattern":"Error sending OneBot message: (.+?)","errorType":"exception","errorClass":"NotifierException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs","lineNumber":92,"sourceCode":"                var groupResponse = await SendMessage(url, content, false);\n                if (!groupResponse)\n                {\n                    success = false;\n                }\n            }\n\n            if (!success)\n            {\n                throw new NotifierException(\"OneBot message sending failed\");\n            }\n        }\n        catch (NotifierException)\n        {\n            throw;\n        }\n        catch (System.Exception ex)\n        {\n            throw new NotifierException($\"Error sending OneBot message: {ex.Message}\");\n        }\n    }\n\n    private async Task<bool> SendMessage(string url, BaseNotificationData content, bool isPrivate)\n    {\n        // 构建消息内容\n        var messageContent = new List<object>\n        {\n            new\n            {\n                type = \"text\",\n                data = new { text = content.Message }\n            }\n        };\n\n        // 如果有截图，添加图片消息\n        if (content.Screenshot != null)\n        {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs#L74-L110","documentation":"Catch-all wrapper around SendAsync: any non-NotifierException (network, DNS, JSON parse of the OneBot response, ObjectDisposedException on the HttpClient) is re-wrapped as a NotifierException. Note it loses the original exception as InnerException.","triggerScenarios":"HttpClient.SendAsync throws HttpRequestException (DNS/connection refused); JsonDocument.Parse throws JsonException on a non-JSON OneBot error page; the connection is reset.","commonSituations":"OneBot framework not running on the configured host:port; firewall blocks loopback-to-loopback on a containerized setup; the endpoint returns HTML (reverse proxy error page) so JSON parsing fails.","solutions":["Preserve ex as InnerException for stack-trace diagnosis.","Separate HttpRequestException (network) from JsonException (bad response) for clearer messages.","Confirm the OneBot HTTP server is listening on the endpoint host/port and reachable.","If behind a reverse proxy, ensure it returns JSON, not an HTML error page."],"exampleFix":"// before\ncatch (System.Exception ex)\n{\n    throw new NotifierException($\"Error sending OneBot message: {ex.Message}\");\n}\n\n// after\ncatch (HttpRequestException ex)\n{\n    throw new NotifierException($\"OneBot network error: {ex.Message}\", ex);\n}\ncatch (JsonException ex)\n{\n    throw new NotifierException($\"OneBot returned non-JSON response: {ex.Message}\", ex);\n}\ncatch (System.Exception ex)\n{\n    throw new NotifierException($\"Error sending OneBot message: {ex.Message}\", ex);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await oneBotNotifier.SendAsync(data); }\ncatch (NotifierException ex) when (ex.Message.StartsWith(\"Error sending OneBot\"))\n{ /* network/transport or non-JSON response — check OneBot server reachability */ }","preventionTips":["Confirm the OneBot HTTP server is listening and reachable.","Ensure any reverse proxy returns JSON, not HTML error pages.","Preserve inner exceptions for diagnosis."],"tags":["onebot","network","catch-all","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}