using Grpc.Core; using MxGateway.Contracts.Proto; namespace MxGateway.Client; /// /// Exception thrown when a gateway RPC call fails or returns an error status. /// public class MxGatewayException : Exception { /// /// Initializes a new instance of the MxGatewayException class with the specified message. /// /// Diagnostic message describing the failure. public MxGatewayException(string message) : base(message) { Statuses = []; } /// /// Initializes a new instance of the MxGatewayException class with the specified message and inner exception. /// /// Diagnostic message describing the failure. /// Underlying exception that caused this failure. public MxGatewayException(string message, Exception? innerException) : base(message, innerException) { Statuses = []; } /// /// Initializes a new instance of the MxGatewayException class carrying the originating /// gRPC status code so callers can distinguish transient from permanent failures. /// /// Diagnostic message describing the failure. /// The gRPC status code reported by the failed call. /// Underlying exception that caused this failure. public MxGatewayException(string message, StatusCode statusCode, Exception? innerException) : base(message, innerException) { StatusCode = statusCode; Statuses = []; } /// /// Initializes a new instance of the MxGatewayException class with full diagnostic information. /// /// Diagnostic message describing the failure. /// Session ID associated with the exception, if available. /// Correlation ID associated with the exception, if available. /// Protocol-level status returned by the gateway, if available. /// HRESULT code returned by the worker or MXAccess, if available. /// List of MXAccess status codes returned by the operation. /// Underlying exception that caused this failure. /// The gRPC status code reported by the failed call, if available. public MxGatewayException( string message, string? sessionId, string? correlationId, ProtocolStatus? protocolStatus, int? hResult, IReadOnlyList statuses, Exception? innerException = null, StatusCode? statusCode = null) : base(message, innerException) { SessionId = sessionId; CorrelationId = correlationId; ProtocolStatus = protocolStatus; HResultCode = hResult; Statuses = statuses; StatusCode = statusCode; } /// /// Gets the session ID associated with the exception, if available. /// public string? SessionId { get; } /// /// Gets the correlation ID associated with the exception, if available. /// public string? CorrelationId { get; } /// /// Gets the protocol-level status returned by the gateway, if available. /// public ProtocolStatus? ProtocolStatus { get; } /// /// Gets the HRESULT code returned by the worker or MXAccess, if available. /// public int? HResultCode { get; } /// /// Gets the list of MXAccess status codes returned by the operation. /// public IReadOnlyList Statuses { get; } /// /// Gets the gRPC status code reported by the failed call, if the failure originated /// from a gRPC . when the exception /// was not produced from a gRPC status (for example, a protocol-level reply failure). /// Callers can inspect this to distinguish a transient outage /// () from a permanent error /// () without downcasting /// . /// public StatusCode? StatusCode { get; } }