| | | 1 | | namespace TeleFlow.Telegram; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Describes one syntactically valid Telegram update that could not be mapped to the installed schema. |
| | | 5 | | /// Applications can persist the raw payload before explicitly allowing the transport to skip it. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed class TelegramUpdateDecodeFailure |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Creates evidence for one update schema failure without exposing the raw payload through <see cref="ToString"/>. |
| | | 11 | | /// </summary> |
| | | 12 | | public TelegramUpdateDecodeFailure( |
| | | 13 | | TelegramUpdateTransport transport, |
| | | 14 | | long updateId, |
| | | 15 | | string rawPayloadJson, |
| | | 16 | | string payloadSha256, |
| | | 17 | | TelegramUpdateDecodeException exception) |
| | | 18 | | { |
| | 8 | 19 | | ArgumentException.ThrowIfNullOrWhiteSpace(rawPayloadJson); |
| | 8 | 20 | | ArgumentException.ThrowIfNullOrWhiteSpace(payloadSha256); |
| | 8 | 21 | | ArgumentNullException.ThrowIfNull(exception); |
| | | 22 | | |
| | 8 | 23 | | if (exception.UpdateId != updateId) |
| | | 24 | | { |
| | 0 | 25 | | throw new ArgumentException("The decode exception belongs to a different Telegram update.", nameof(exception |
| | | 26 | | } |
| | | 27 | | |
| | 8 | 28 | | if (!string.Equals(exception.PayloadSha256, payloadSha256, StringComparison.Ordinal)) |
| | | 29 | | { |
| | 0 | 30 | | throw new ArgumentException("The decode exception contains a different payload fingerprint.", nameof(excepti |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | Transport = transport; |
| | | 34 | | UpdateId = updateId; |
| | | 35 | | RawPayloadJson = rawPayloadJson; |
| | | 36 | | PayloadSha256 = payloadSha256; |
| | | 37 | | Exception = exception; |
| | 8 | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary>Gets the transport that received the incompatible update.</summary> |
| | | 41 | | public TelegramUpdateTransport Transport { get; } |
| | | 42 | | |
| | | 43 | | /// <summary>Gets the Telegram update identifier used for acknowledgement ordering.</summary> |
| | | 44 | | public long UpdateId { get; } |
| | | 45 | | |
| | | 46 | | /// <summary>Gets the complete raw JSON update for durable quarantine.</summary> |
| | | 47 | | public string RawPayloadJson { get; } |
| | | 48 | | |
| | | 49 | | /// <summary>Gets the lowercase SHA-256 fingerprint of <see cref="RawPayloadJson"/>.</summary> |
| | | 50 | | public string PayloadSha256 { get; } |
| | | 51 | | |
| | | 52 | | /// <summary>Gets the structured schema decode exception.</summary> |
| | | 53 | | public TelegramUpdateDecodeException Exception { get; } |
| | | 54 | | |
| | | 55 | | public override string ToString() |
| | | 56 | | { |
| | 0 | 57 | | return $"Telegram update {UpdateId} failed schema decoding on {Transport}; payload_sha256={PayloadSha256}."; |
| | | 58 | | } |
| | | 59 | | } |