| | | 1 | | using System.Text; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Telegram.Internal; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents a typed callback route payload that matched the expected callback data |
| | | 7 | | /// shape but could not be decoded before handler selection. |
| | | 8 | | /// </summary> |
| | | 9 | | internal sealed class CallbackDataRouteDeserializationException : Exception |
| | | 10 | | { |
| | | 11 | | public CallbackDataRouteDeserializationException( |
| | | 12 | | Type payloadType, |
| | | 13 | | string serializedPayload, |
| | | 14 | | Exception innerException) |
| | 2 | 15 | | : base( |
| | 2 | 16 | | CreateMessage(payloadType), |
| | 2 | 17 | | innerException ?? throw new ArgumentNullException(nameof(innerException))) |
| | | 18 | | { |
| | 2 | 19 | | ArgumentNullException.ThrowIfNull(payloadType); |
| | 2 | 20 | | ArgumentNullException.ThrowIfNull(serializedPayload); |
| | | 21 | | |
| | | 22 | | PayloadType = payloadType; |
| | 2 | 23 | | PayloadByteCount = Encoding.UTF8.GetByteCount(serializedPayload); |
| | 2 | 24 | | } |
| | | 25 | | |
| | | 26 | | public Type PayloadType { get; } |
| | | 27 | | |
| | | 28 | | public int PayloadByteCount { get; } |
| | | 29 | | |
| | | 30 | | private static string CreateMessage(Type payloadType) |
| | | 31 | | { |
| | 2 | 32 | | ArgumentNullException.ThrowIfNull(payloadType); |
| | | 33 | | |
| | 2 | 34 | | return $"Telegram callback data matched payload type '{payloadType.FullName}' but could not be deserialized."; |
| | | 35 | | } |
| | | 36 | | } |