{"record":{"id":"a69ea6e5d1eb96d9","repo":"babalae/better-genshin-impact","slug":"network-error-sending-telegram-notification-ex-m","errorCode":null,"errorMessage":"Network error sending Telegram notification: {ex.Message}","messagePattern":"Network error sending Telegram notification: (.+?)","errorType":"exception","errorClass":"NotifierException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs","lineNumber":130,"sourceCode":"    public async Task SendAsync(BaseNotificationData content)\n    {\n        if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException(\"Telegram bot token is not set\");\n        if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException(\"Telegram chat ID is not set\");\n        if (string.IsNullOrEmpty(content.Message)) throw new NotifierException(\"No message content to send\");\n\n        try\n        {\n            if (content.Screenshot != null)\n            {\n                await SendImageMessageAsync(content.Screenshot, content.Message.Length < 1024 ? content.Message : null);\n                if (content.Message.Length < 1024) return;\n            }\n\n            await SendTextMessageAsync(content.Message);\n        }\n        catch (HttpRequestException ex)\n        {\n            throw new NotifierException(\"Network error sending Telegram notification: \" + ex.Message);\n        }\n        catch (TaskCanceledException)\n        {\n            throw new NotifierException(\"Telegram API request timed out. Check your internet connection.\");\n        }\n        catch (System.Exception ex) when (ex is not NotifierException)\n        {\n            throw new NotifierException(\"Error sending Telegram notification: \" + ex.Message);\n        }\n    }\n\n    private async Task SendImageMessageAsync(Image<Rgb24> image, string? caption)\n    {\n        var endpoint = $\"{TelegramApiBaseUrl}{TelegramBotToken}/sendPhoto\";\n        using var memoryStream = new MemoryStream();\n        await image.SaveAsPngAsync(memoryStream);\n        memoryStream.Position = 0;\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs#L112-L148","documentation":"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.","triggerScenarios":"_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.","commonSituations":"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.","solutions":["Verify network connectivity and that api.telegram.org (or the custom TelegramApiBaseUrl) resolves.","If in a restricted region, configure a working proxy and confirm ProxyEnabled + ProxyUrl.","Inspect ex.StatusCode (if present) to distinguish 5xx from connection failures.","Retry transient HttpRequestException with backoff before surfacing."],"exampleFix":"// before\ncatch (HttpRequestException ex)\n{\n    throw new NotifierException(\"Network error sending Telegram notification: \" + ex.Message);\n}\n\n// after\ncatch (HttpRequestException ex)\n{\n    var detail = ex.StatusCode.HasValue ? $\"HTTP {(int)ex.StatusCode}\" : \"connection/DNS failure\";\n    throw new NotifierException($\"Network error sending Telegram notification ({detail}): {ex.Message}\", ex);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (int attempt = 0; ; attempt++)\ntry { await telegramNotifier.SendAsync(data); break; }\ncatch (NotifierException ex) when (ex.Message.Contains(\"Network error\") && attempt < 2)\n{ await Task.Delay(TimeSpan.FromSeconds(2 * (attempt + 1))); }","preventionTips":["Confirm api.telegram.org (or the custom API base URL) is reachable.","If region-blocked, configure a working proxy.","Retry transient HttpRequestException with backoff before reporting failure."],"tags":["telegram","network","proxy","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}