in iothub/device/src/Transport/AmqpIot/AmqpIotErrorAdapter.cs [186:274]
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 = $"{message}\r\nTracking 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/azure/iot-hub/iot-hub-troubleshoot-error-403004-devicemaximumqueuedepthexceeded
// Error code 403002 is applicable to D2C (Device client); see https://docs.microsoft.com/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 hubEx)
{
hubEx.TrackingId = trackingId;
}
return retException;
}