internal static Exception ConvertToIotHubException(Exception exception)
        {
            if (exception is TimeoutException)
            {
                return(new IotHubCommunicationException(exception.Message, exception));
            }

            if (exception is UnauthorizedAccessException)
            {
                return(new UnauthorizedException(exception.Message, exception));
            }

            if (exception is OperationCanceledException &&
                exception.InnerException is AmqpException innerAmqpException &&
                innerAmqpException != null)
            {
                return(AmqpIotErrorAdapter.ToIotHubClientContract(innerAmqpException));
            }

            if (exception is AmqpException amqpException &&
                amqpException != null)
            {
                return(AmqpIotErrorAdapter.ToIotHubClientContract(amqpException));
            }

            return(exception);
        }
예제 #2
0
 public void ThrowIfNotAccepted()
 {
     if (_outcome.DescriptorCode != Accepted.Code)
     {
         throw AmqpIotErrorAdapter.GetExceptionFromOutcome(_outcome);
     }
 }
 internal static Exception ConvertToIotHubException(Exception exception)
 {
     if (exception is TimeoutException)
     {
         return(new IotHubCommunicationException(exception.Message, exception));
     }
     else if (exception is UnauthorizedAccessException)
     {
         return(new UnauthorizedException(exception.Message, exception));
     }
     else
     {
         var amqpException = exception as AmqpException;
         return(amqpException == null
             ? exception
             : AmqpIotErrorAdapter.ToIotHubClientContract(amqpException));
     }
 }
예제 #4
0
        public void ThrowIfError()
        {
            if (_outcome.DescriptorCode != Accepted.Code)
            {
                if (_outcome.DescriptorCode == Rejected.Code)
                {
                    var rejected = (Rejected)_outcome;

                    // Special treatment for NotFound amqp rejected error code in case of DisposeMessage
                    if (rejected.Error != null && rejected.Error.Condition.Equals(AmqpErrorCode.NotFound))
                    {
                        var error = new Error
                        {
                            Condition = AmqpIotErrorAdapter.MessageLockLostError,
                        };
                        throw AmqpIotErrorAdapter.ToIotHubClientContract(error);
                    }
                }

                throw AmqpIotErrorAdapter.GetExceptionFromOutcome(_outcome);
            }
        }