< Summary

Information
Class: TeleFlow.Telegram.Internal.TelegramApiExceptionFactory
Assembly: TeleFlow.Telegram.Client
File(s): /_/src/TeleFlow.Telegram.Client/Internal/TelegramApiExceptionFactory.cs
Line coverage
90%
Covered lines: 60
Uncovered lines: 6
Coverable lines: 66
Total lines: 87
Line coverage: 90.9%
Branch coverage
86%
Covered branches: 19
Total branches: 22
Branch coverage: 86.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsThrottling(...)100%22100%
CreateApiException(...)85%202090.76%

File(s)

/_/src/TeleFlow.Telegram.Client/Internal/TelegramApiExceptionFactory.cs

#LineLine coverage
 1namespace TeleFlow.Telegram.Internal;
 2
 3internal static class TelegramApiExceptionFactory
 4{
 5    public static bool IsThrottling(int statusCode, TelegramTransportEnvelope envelope)
 6    {
 497        return statusCode == 429 || envelope.ErrorCode == 429;
 8    }
 9
 10    public static TelegramRequestException CreateApiException(
 11        string methodName,
 12        int statusCode,
 13        TelegramTransportEnvelope envelope,
 14        string? fallbackDescription = null)
 15    {
 1616        var description = envelope.Description ?? fallbackDescription;
 1617        var message = description is null
 1618            ? $"Telegram request '{methodName}' failed."
 1619            : $"Telegram request '{methodName}' failed: {description}";
 1620        var httpStatusCode = statusCode;
 1621        var telegramErrorCode = envelope.ErrorCode;
 22
 1623        if (envelope.ResponseParameters?.MigrateToChatId is long migrateToChatId)
 24        {
 125            return new TelegramMigrateToChatException(
 126                message,
 127                methodName,
 128                httpStatusCode,
 129                telegramErrorCode,
 130                description,
 131                migrateToChatId);
 32        }
 33
 1534        return statusCode switch
 1535        {
 536            400 => new TelegramBadRequestException(
 537                message,
 538                methodName,
 539                httpStatusCode,
 540                telegramErrorCode,
 541                description),
 142            401 => new TelegramUnauthorizedException(
 143                message,
 144                methodName,
 145                httpStatusCode,
 146                telegramErrorCode,
 147                description),
 148            403 => new TelegramForbiddenException(
 149                message,
 150                methodName,
 151                httpStatusCode,
 152                telegramErrorCode,
 153                description),
 154            404 => new TelegramNotFoundException(
 155                message,
 156                methodName,
 157                httpStatusCode,
 158                telegramErrorCode,
 159                description),
 160            409 => new TelegramConflictException(
 161                message,
 162                methodName,
 163                httpStatusCode,
 164                telegramErrorCode,
 165                description),
 166            413 => new TelegramEntityTooLargeException(
 167                message,
 168                methodName,
 169                httpStatusCode,
 170                telegramErrorCode,
 171                description),
 1072            _ when statusCode >= 500 => new TelegramServerException(
 573                message,
 574                methodName,
 575                httpStatusCode,
 576                telegramErrorCode,
 577                description),
 078            _ => new TelegramApiException(
 079                message,
 080                methodName: methodName,
 081                httpStatusCode: httpStatusCode,
 082                telegramErrorCode: telegramErrorCode,
 083                description: description)
 1584        };
 85    }
 86
 87}