private void throwDeviceNotFoundException(string name) { string message = "Cannot establish connection to controller. Maybe the device is not properly connected, the wire is to long or the wrong sketch is uploaded."; var exception = new DeviceNotFoundException(name, message); Logger.Error(exception, message); throw exception; }
public void ExceptionInvalidDeviceName() { // arrange var exception = new DeviceNotFoundException("param", "watch", "test"); // act var message = exception.Message; // assert Assert.Equal("test\r\nParameter name: param\r\nwatch", message); }
public void ExceptionNotNull() { // arrange var exception = new DeviceNotFoundException("test"); // act var message = exception.Message; // assert Assert.Equal("test", message); }
public void ExceptionDefaultBehavuor() { // arrange var exception = new DeviceNotFoundException(); // act var message = exception.Message; // assert Assert.Equal("Device Not Supported", message); }
public void ExceptionWithInnerException() { // arrange var inner = new Exception("inner"); var exception = new DeviceNotFoundException("test", inner); // act var message = exception.Message; // assert Assert.Equal("test", message); }
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(AmqpIotConstants.TrackingId, out trackingId)) { message = "{0}{1}{2}".FormatInvariant(message, Environment.NewLine, "Tracking Id:" + trackingId); } if (error.Condition.Equals(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(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(ArgumentError)) { retException = new ArgumentException(message); } else if (error.Condition.Equals(ArgumentOutOfRangeError)) { retException = new ArgumentOutOfRangeException(message); } else if (error.Condition.Equals(AmqpErrorCode.MessageSizeExceeded)) { retException = new MessageTooLargeException(message); } else if (error.Condition.Equals(AmqpErrorCode.ResourceLimitExceeded)) { // Note: The DeviceMaximumQueueDepthExceededException is not supposed to be thrown here as it is being mapped to the incorrect error code // Error code 403004 is only applicable to C2D (Service client); see https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-troubleshoot-error-403004-devicemaximumqueuedepthexceeded // Error code 403002 is applicable to D2C (Device client); see https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-troubleshoot-error-403002-iothubquotaexceeded // We have opted not to change the exception type thrown here since it will be a breaking change, alternatively, we are adding the correct exception type // as the inner exception. retException = new DeviceMaximumQueueDepthExceededException( $"Please check the inner exception for more information.\n " + $"The correct exception type is `{nameof(QuotaExceededException)}` " + $"but since that is a breaking change to the current behavior in the SDK, you can refer to the inner exception " + $"for more information. Exception message: {message}", new QuotaExceededException(message)); } else if (error.Condition.Equals(DeviceContainerThrottled)) { retException = new IotHubThrottledException(message, null); } else if (error.Condition.Equals(IotHubSuspended)) { retException = new IotHubSuspendedException(message); } else { retException = new IotHubException(message); } if (trackingId != null && retException is IotHubException) { var iotHubException = (IotHubException)retException; iotHubException.TrackingId = trackingId; } return(retException); }
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(TrackingId, out trackingId)) { message = "{0}{1}{2}".FormatInvariant(message, Environment.NewLine, "Tracking Id:" + trackingId); } if (error.Condition.Equals(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(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(ArgumentError)) { retException = new ArgumentException(message); } else if (error.Condition.Equals(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(DeviceAlreadyExists)) { retException = new DeviceAlreadyExistsException(message, null); } else if (error.Condition.Equals(DeviceContainerThrottled)) { retException = new IotHubThrottledException(message, null); } else if (error.Condition.Equals(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); }