示例#1
0
        /// <summary>
        /// This method handles the case where the peer is potentially down. If the Rpc call
        /// put the channel in TransientFailure or Connecting, we give the connection a certain time to recover.
        /// </summary>
        private NetworkException CreateNetworkException(Exception exception, string errorMessage)
        {
            string message            = $"Failed request to {this}: {errorMessage}";
            NetworkExceptionType type = NetworkExceptionType.Rpc;

            if (_channel.State != ChannelState.Ready)
            {
                // if channel has been shutdown (unrecoverable state) remove it.
                if (_channel.State == ChannelState.Shutdown)
                {
                    message = $"Peer is shutdown - {this}: {errorMessage}";
                    type    = NetworkExceptionType.Unrecoverable;
                }
                else if (_channel.State == ChannelState.TransientFailure || _channel.State == ChannelState.Connecting)
                {
                    // from this we try to recover
                    message = $"Peer is unstable - {this}: {errorMessage}";
                    type    = NetworkExceptionType.PeerUnstable;
                }
                else
                {
                    // if idle just after an exception, disconnect.
                    message = $"Peer error, channel state {_channel.State} - {this}: {errorMessage}";
                    type    = NetworkExceptionType.Unrecoverable;
                }
            }
            else
            {
                // there was an exception, not related to connectivity.
                if (exception.InnerException is RpcException rpcEx)
                {
                    if (rpcEx.StatusCode == StatusCode.Cancelled)
                    {
                        message = $"Request was cancelled {this}: {errorMessage}";
                        type    = NetworkExceptionType.Unrecoverable;
                    }
                    else if (rpcEx.StatusCode == StatusCode.Unknown)
                    {
                        message = $"Exception in handler {this}: {errorMessage}";
                        type    = NetworkExceptionType.HandlerException;
                    }
                }
            }

            return(new NetworkException(message, exception, type));
        }
示例#2
0
        /// <summary>
        /// This method handles the case where the peer is potentially down. If the Rpc call
        /// put the channel in TransientFailure or Connecting, we give the connection a certain time to recover.
        /// </summary>
        private void HandleFailure(Exception exception, string errorMessage)
        {
            // If channel has been shutdown (unrecoverable state) remove it.
            string message            = $"Failed request to {this}: {errorMessage}";
            NetworkExceptionType type = NetworkExceptionType.Rpc;

            if (_channel.State == ChannelState.Shutdown)
            {
                message = $"Peer is shutdown - {this}: {errorMessage}";
                type    = NetworkExceptionType.Unrecoverable;
            }
            else if (_channel.State == ChannelState.TransientFailure || _channel.State == ChannelState.Connecting)
            {
                message = $"Failed request to {this}: {errorMessage}";
                type    = NetworkExceptionType.PeerUnstable;
            }
            else if (exception.InnerException is RpcException rpcEx && rpcEx.StatusCode == StatusCode.Cancelled)
            {
                message = $"Failed request to {this}: {errorMessage}";
                type    = NetworkExceptionType.Unrecoverable;
            }

            throw new NetworkException(message, exception, type);
        }
 public NetworkException(NetworkExceptionType exceptionType, Exception innerException) : base($"{exceptionType}", innerException)
 {
     ExceptionType = exceptionType;
 }
 public NetworkException(NetworkExceptionType exceptionType, string message) : base($"{exceptionType}: {message}")
 {
     ExceptionType = exceptionType;
 }
 public NetworkException(NetworkExceptionType exceptionType) : base($"{exceptionType}")
 {
     ExceptionType = exceptionType;
 }
 public NetworkingException(string message, NetworkExceptionType networkExceptionType, Exception innerException) : base(message, innerException)
 {
     NetworkExceptionType = networkExceptionType;
 }
 public NetworkingException(string message, NetworkExceptionType networkExceptionType)
     : base(message)
 {
     NetworkExceptionType = networkExceptionType;
 }
示例#8
0
 public NetworkException(string message, Exception inner,
                         NetworkExceptionType exceptionType = NetworkExceptionType.Rpc) : base(message, inner)
 {
     ExceptionType = exceptionType;
 }
示例#9
0
 public NetworkException(string message, NetworkExceptionType exceptionType) : base(message)
 {
     ExceptionType = exceptionType;
 }