babalae/better-genshin-impact · error · NotifierException

Network error sending Telegram notification: {ex.Message}

Error message

Network error sending Telegram notification: {ex.Message}

What it means

Wraps HttpRequestException thrown during SendImageMessageAsync/SendTextMessageAsync/SendRequestAsync — i.e. a transport/HTTP-layer failure: DNS failure, connection refused, TLS handshake error, 5xx from the Telegram API server, or a non-success that HttpRequestException surfaces. Distinct from the application-level 4xx handled via ValidateApiResponse.

Source

Thrown at BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs:130

    public async Task SendAsync(BaseNotificationData content)
    {
        if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException("Telegram bot token is not set");
        if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException("Telegram chat ID is not set");
        if (string.IsNullOrEmpty(content.Message)) throw new NotifierException("No message content to send");

        try
        {
            if (content.Screenshot != null)
            {
                await SendImageMessageAsync(content.Screenshot, content.Message.Length < 1024 ? content.Message : null);
                if (content.Message.Length < 1024) return;
            }

            await SendTextMessageAsync(content.Message);
        }
        catch (HttpRequestException ex)
        {
            throw new NotifierException("Network error sending Telegram notification: " + ex.Message);
        }
        catch (TaskCanceledException)
        {
            throw new NotifierException("Telegram API request timed out. Check your internet connection.");
        }
        catch (System.Exception ex) when (ex is not NotifierException)
        {
            throw new NotifierException("Error sending Telegram notification: " + ex.Message);
        }
    }

    private async Task SendImageMessageAsync(Image<Rgb24> image, string? caption)
    {
        var endpoint = $"{TelegramApiBaseUrl}{TelegramBotToken}/sendPhoto";
        using var memoryStream = new MemoryStream();
        await image.SaveAsPngAsync(memoryStream);
        memoryStream.Position = 0;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify network connectivity and that api.telegram.org (or the custom TelegramApiBaseUrl) resolves.
  2. If in a restricted region, configure a working proxy and confirm ProxyEnabled + ProxyUrl.
  3. Inspect ex.StatusCode (if present) to distinguish 5xx from connection failures.
  4. Retry transient HttpRequestException with backoff before surfacing.

Example fix

// before
catch (HttpRequestException ex)
{
    throw new NotifierException("Network error sending Telegram notification: " + ex.Message);
}

// after
catch (HttpRequestException ex)
{
    var detail = ex.StatusCode.HasValue ? $"HTTP {(int)ex.StatusCode}" : "connection/DNS failure";
    throw new NotifierException($"Network error sending Telegram notification ({detail}): {ex.Message}", ex);
}
Defensive patterns

Strategy: retry

Try / catch

for (int attempt = 0; ; attempt++)
try { await telegramNotifier.SendAsync(data); break; }
catch (NotifierException ex) when (ex.Message.Contains("Network error") && attempt < 2)
{ await Task.Delay(TimeSpan.FromSeconds(2 * (attempt + 1))); }

Prevention

When it happens

Trigger: _httpClient.SendAsync throws HttpRequestException; common when api.telegram.org is unreachable, the proxy (if set) refuses connection, or Telegram returns 5xx that the HTTP stack raises as an exception in some configurations.

Common situations: No internet; Telegram blocked in the region and no/incorrect proxy configured; proxy down; DNS resolution failure for api.telegram.org or the custom API base URL.

Related errors


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