public static Exception GetExceptionFromOutcome(Outcome outcome)
        {
            Exception retException = null;

            if (outcome == null)
            {
                retException = new IotHubException("Unknown error.");
                return(retException);
            }

            if (outcome.DescriptorCode == Rejected.Code)
            {
                var rejected = (Rejected)outcome;
                retException = AmqpErrorMapper.ToIotHubClientContract(rejected.Error);
            }
            else if (outcome.DescriptorCode == Released.Code)
            {
                retException = new OperationCanceledException("AMQP link released.");
            }
            else
            {
                retException = new IotHubException("Unknown error.");
            }

            return(retException);
        }
Beispiel #2
0
        public static Exception ToIotHubClientContract(Exception exception)
        {
            if (exception is TimeoutException)
            {
                return(new IotHubCommunicationException(exception.Message));
            }
            else if (exception is UnauthorizedAccessException)
            {
                return(new UnauthorizedException(exception.Message));
            }
            else
            {
                var amqpException = exception as AmqpException;
                if (amqpException != null)
                {
                    return(AmqpErrorMapper.ToIotHubClientContract(amqpException.Error));
                }

                return(exception);
            }
        }