babalae/better-genshin-impact · error · NotifierException

Error sending OneBot message: {ex.Message}

Error message

Error sending OneBot message: {ex.Message}

What it means

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.

Source

Thrown at BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs:92

                var groupResponse = await SendMessage(url, content, false);
                if (!groupResponse)
                {
                    success = false;
                }
            }

            if (!success)
            {
                throw new NotifierException("OneBot message sending failed");
            }
        }
        catch (NotifierException)
        {
            throw;
        }
        catch (System.Exception ex)
        {
            throw new NotifierException($"Error sending OneBot message: {ex.Message}");
        }
    }

    private async Task<bool> SendMessage(string url, BaseNotificationData content, bool isPrivate)
    {
        // 构建消息内容
        var messageContent = new List<object>
        {
            new
            {
                type = "text",
                data = new { text = content.Message }
            }
        };

        // 如果有截图,添加图片消息
        if (content.Screenshot != null)
        {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Preserve ex as InnerException for stack-trace diagnosis.
  2. Separate HttpRequestException (network) from JsonException (bad response) for clearer messages.
  3. Confirm the OneBot HTTP server is listening on the endpoint host/port and reachable.
  4. If behind a reverse proxy, ensure it returns JSON, not an HTML error page.

Example fix

// before
catch (System.Exception ex)
{
    throw new NotifierException($"Error sending OneBot message: {ex.Message}");
}

// after
catch (HttpRequestException ex)
{
    throw new NotifierException($"OneBot network error: {ex.Message}", ex);
}
catch (JsonException ex)
{
    throw new NotifierException($"OneBot returned non-JSON response: {ex.Message}", ex);
}
catch (System.Exception ex)
{
    throw new NotifierException($"Error sending OneBot message: {ex.Message}", ex);
}
Defensive patterns

Strategy: try-catch

Try / catch

try { await oneBotNotifier.SendAsync(data); }
catch (NotifierException ex) when (ex.Message.StartsWith("Error sending OneBot"))
{ /* network/transport or non-JSON response — check OneBot server reachability */ }

Prevention

When it happens

Trigger: HttpClient.SendAsync throws HttpRequestException (DNS/connection refused); JsonDocument.Parse throws JsonException on a non-JSON OneBot error page; the connection is reset.

Common situations: 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.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/a3ca572b00231649. Report an issue: GitHub.