static MessagingException ComposeIotHubCommunicationException(IotHubException ex) { return new MessagingException(ex.Message, ex.InnerException, ex.IsTransient, ex.TrackingId); }
public static Exception ToIotHubClientContract(Error error) { Exception retException; if (error == null) { retException = new IotHubException("Unknown error."); return retException; } string message = error.Description; string trackingId = null; if (error.Info != null && error.Info.TryGetValue(IotHubAmqpProperty.TrackingId, out trackingId)) { message = "{0}{1}{2}".FormatInvariant(message, Environment.NewLine, "Tracking Id:" + trackingId); } if (error.Condition.Equals(IotHubAmqpErrorCode.TimeoutError)) { retException = new TimeoutException(message); } else if (error.Condition.Equals(AmqpErrorCode.NotFound)) { retException = new DeviceNotFoundException(message, (Exception)null); } else if (error.Condition.Equals(AmqpErrorCode.NotImplemented)) { retException = new NotSupportedException(message); } else if (error.Condition.Equals(IotHubAmqpErrorCode.MessageLockLostError)) { retException = new DeviceMessageLockLostException(message); } else if (error.Condition.Equals(AmqpErrorCode.NotAllowed)) { retException = new InvalidOperationException(message); } else if (error.Condition.Equals(AmqpErrorCode.UnauthorizedAccess)) { retException = new UnauthorizedException(message); } else if (error.Condition.Equals(IotHubAmqpErrorCode.ArgumentError)) { retException = new ArgumentException(message); } else if (error.Condition.Equals(IotHubAmqpErrorCode.ArgumentOutOfRangeError)) { retException = new ArgumentOutOfRangeException(message); } else if (error.Condition.Equals(AmqpErrorCode.MessageSizeExceeded)) { retException = new MessageTooLargeException(message); } else if (error.Condition.Equals(AmqpErrorCode.ResourceLimitExceeded)) { retException = new DeviceMaximumQueueDepthExceededException(message); } else if (error.Condition.Equals(IotHubAmqpErrorCode.DeviceAlreadyExists)) { retException = new DeviceAlreadyExistsException(message, null); } else if (error.Condition.Equals(IotHubAmqpErrorCode.DeviceContainerThrottled)) { retException = new IotHubThrottledException(message, null); } else if (error.Condition.Equals(IotHubAmqpErrorCode.IotHubSuspended)) { retException = new IotHubSuspendedException(message); } else { retException = new IotHubException(message); } if (trackingId != null && retException is IotHubException) { IotHubException iotHubException = (IotHubException) retException; iotHubException.TrackingId = trackingId; } return retException; }
void ProcessConnectAck(IChannelHandlerContext context, ConnAckPacket packet) { if (packet.ReturnCode != ConnectReturnCode.Accepted) { string reason = "CONNECT failed: " + packet.ReturnCode; var iotHubException = new IotHubException(reason); ShutdownOnError(context, iotHubException); return; } if (!this.IsInState(StateFlags.Connecting)) { string reason = "CONNECT has been received, however a session has already been established. Only one CONNECT/CONNACK pair is expected per session."; var iotHubException = new IotHubException(reason); ShutdownOnError(context, iotHubException); return; } this.stateFlags = StateFlags.Connected; this.ResumeReadingIfNecessary(context); this.onConnected(); }
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; }