| | | 1 | | namespace AsiBackbone.Core.Emissions; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents provider-neutral error information for a governance emission attempt. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class GovernanceEmissionError |
| | | 7 | | { |
| | 66 | 8 | | private GovernanceEmissionError( |
| | 66 | 9 | | string code, |
| | 66 | 10 | | string message, |
| | 66 | 11 | | bool isRetryable, |
| | 66 | 12 | | string? providerName, |
| | 66 | 13 | | string? providerErrorCode) |
| | | 14 | | { |
| | 66 | 15 | | ArgumentException.ThrowIfNullOrWhiteSpace(code); |
| | 65 | 16 | | ArgumentException.ThrowIfNullOrWhiteSpace(message); |
| | | 17 | | |
| | 64 | 18 | | Code = code.Trim(); |
| | 64 | 19 | | Message = message.Trim(); |
| | 64 | 20 | | IsRetryable = isRetryable; |
| | 64 | 21 | | ProviderName = NormalizeOptional(providerName); |
| | 64 | 22 | | ProviderErrorCode = NormalizeOptional(providerErrorCode); |
| | 64 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the provider-neutral error code. |
| | | 27 | | /// </summary> |
| | 46 | 28 | | public string Code { get; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets the provider-neutral diagnostic message. |
| | | 32 | | /// </summary> |
| | 22 | 33 | | public string Message { get; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets a value indicating whether the error is expected to be retryable. |
| | | 37 | | /// </summary> |
| | 51 | 38 | | public bool IsRetryable { get; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the provider name associated with the error, when available. |
| | | 42 | | /// </summary> |
| | 72 | 43 | | public string? ProviderName { get; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets the provider-specific error code, when safe and available. |
| | | 47 | | /// </summary> |
| | 21 | 48 | | public string? ProviderErrorCode { get; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Creates provider-neutral error information for a governance emission attempt. |
| | | 52 | | /// </summary> |
| | | 53 | | /// <param name="code">The provider-neutral error code.</param> |
| | | 54 | | /// <param name="message">The provider-neutral diagnostic message.</param> |
| | | 55 | | /// <param name="isRetryable">A value indicating whether the error is expected to be retryable.</param> |
| | | 56 | | /// <param name="providerName">Optional provider name.</param> |
| | | 57 | | /// <param name="providerErrorCode">Optional provider-specific error code.</param> |
| | | 58 | | /// <returns>The governance emission error.</returns> |
| | | 59 | | public static GovernanceEmissionError Create( |
| | | 60 | | string code, |
| | | 61 | | string message, |
| | | 62 | | bool isRetryable = false, |
| | | 63 | | string? providerName = null, |
| | | 64 | | string? providerErrorCode = null) |
| | | 65 | | { |
| | 66 | 66 | | return new GovernanceEmissionError( |
| | 66 | 67 | | code, |
| | 66 | 68 | | message, |
| | 66 | 69 | | isRetryable, |
| | 66 | 70 | | providerName, |
| | 66 | 71 | | providerErrorCode); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | private static string? NormalizeOptional(string? value) |
| | | 75 | | { |
| | 128 | 76 | | return string.IsNullOrWhiteSpace(value) |
| | 128 | 77 | | ? null |
| | 128 | 78 | | : value.Trim(); |
| | | 79 | | } |
| | | 80 | | } |