From abe2b4cf8869f8fcd8da4ca99a5c552388ca74e9 Mon Sep 17 00:00:00 2001
From: "David R. Williamson" <14119884+drwill-ms@users.noreply.github.com>
Date: Mon, 1 May 2023 17:28:42 -0700
Subject: [PATCH] Update service error codes (#3315)
* Update service error codes
* Fix transientness of associated exceptions
---
e2e/test/iothub/DeviceClientE2eTests.cs | 2 --
.../src/Common/Exceptions/IotHubException.cs | 5 ++--
.../Exceptions/IotHubThrottledException.cs | 4 +++-
.../Exceptions/QuotaExceededException.cs | 5 ++--
.../Common/Exceptions/ServerBusyException.cs | 6 +++--
.../src/Common/Exceptions/ErrorCode.cs | 24 +++++++++++++++++++
.../src/Common/Exceptions/IotHubException.cs | 2 +-
.../Exceptions/IotHubThrottledException.cs | 19 ++++-----------
.../Exceptions/JobQuotaExceededException.cs | 9 ++++---
.../Exceptions/QuotaExceededException.cs | 8 ++-----
.../Common/Exceptions/ServerBusyException.cs | 5 ----
.../Common/Exceptions/ThrottlingException.cs | 17 ++++++-------
12 files changed, 58 insertions(+), 48 deletions(-)
diff --git a/e2e/test/iothub/DeviceClientE2eTests.cs b/e2e/test/iothub/DeviceClientE2eTests.cs
index 7511b5e225..b264d8d9b9 100644
--- a/e2e/test/iothub/DeviceClientE2eTests.cs
+++ b/e2e/test/iothub/DeviceClientE2eTests.cs
@@ -36,9 +36,7 @@ public async Task DeviceClient_CloseAsync_CanBeCalledTwice()
finally
{
await testDevice.RemoveDeviceAsync().ConfigureAwait(false);
- testDevice.Dispose();
}
-
}
}
}
diff --git a/iothub/device/src/Common/Exceptions/IotHubException.cs b/iothub/device/src/Common/Exceptions/IotHubException.cs
index b6170a0c8b..d28f6097d9 100644
--- a/iothub/device/src/Common/Exceptions/IotHubException.cs
+++ b/iothub/device/src/Common/Exceptions/IotHubException.cs
@@ -129,7 +129,8 @@ protected IotHubException(SerializationInfo info, StreamingContext context)
}
}
- internal IotHubException(bool isTransient) : base()
+ internal IotHubException(bool isTransient)
+ : base()
{
IsTransient = isTransient;
}
@@ -137,7 +138,7 @@ internal IotHubException(bool isTransient) : base()
///
/// Indicates if the error is transient and should be retried.
///
- public bool IsTransient { get; private set; }
+ public bool IsTransient { get; protected set; }
///
/// The service returned tracking Id associated with this particular error.
diff --git a/iothub/device/src/Common/Exceptions/IotHubThrottledException.cs b/iothub/device/src/Common/Exceptions/IotHubThrottledException.cs
index 7fc1c44fe5..40f78ba605 100644
--- a/iothub/device/src/Common/Exceptions/IotHubThrottledException.cs
+++ b/iothub/device/src/Common/Exceptions/IotHubThrottledException.cs
@@ -20,7 +20,8 @@ public sealed class IotHubThrottledException : IotHubException
///
/// Initializes a new instance of the class.
///
- public IotHubThrottledException() : base(isTransient: true)
+ public IotHubThrottledException()
+ : base(isTransient: true)
{
}
@@ -65,6 +66,7 @@ public IotHubThrottledException(string message, Exception innerException)
private IotHubThrottledException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
+ IsTransient = true;
}
}
}
diff --git a/iothub/device/src/Common/Exceptions/QuotaExceededException.cs b/iothub/device/src/Common/Exceptions/QuotaExceededException.cs
index 29a048326d..42b9d55fa0 100644
--- a/iothub/device/src/Common/Exceptions/QuotaExceededException.cs
+++ b/iothub/device/src/Common/Exceptions/QuotaExceededException.cs
@@ -19,7 +19,8 @@ public sealed class QuotaExceededException : IotHubException
///
/// Initializes a new instance of the class.
///
- public QuotaExceededException() : base(isTransient: true)
+ public QuotaExceededException()
+ : base(isTransient: true)
{
}
@@ -30,7 +31,7 @@ public QuotaExceededException() : base(isTransient: true)
/// understood by humans. The caller of this constructor is required to ensure that this string has
/// been localized for the current system culture.
public QuotaExceededException(string message)
- : this(message, null)
+ : base(message, true)
{
}
diff --git a/iothub/device/src/Common/Exceptions/ServerBusyException.cs b/iothub/device/src/Common/Exceptions/ServerBusyException.cs
index d50e4c23b9..3b24429375 100644
--- a/iothub/device/src/Common/Exceptions/ServerBusyException.cs
+++ b/iothub/device/src/Common/Exceptions/ServerBusyException.cs
@@ -20,7 +20,8 @@ public sealed class ServerBusyException : IotHubException
///
/// Initializes a new instance of the class.
///
- public ServerBusyException() : base(isTransient: true)
+ public ServerBusyException()
+ : base(isTransient: true)
{
}
@@ -29,7 +30,7 @@ public ServerBusyException() : base(isTransient: true)
///
/// The error message.
public ServerBusyException(string message)
- : this(message, null)
+ : base(message, true)
{
}
@@ -43,6 +44,7 @@ public ServerBusyException(string message, Exception innerException)
private ServerBusyException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
+ IsTransient = true;
}
}
}
diff --git a/iothub/service/src/Common/Exceptions/ErrorCode.cs b/iothub/service/src/Common/Exceptions/ErrorCode.cs
index 4b1be0838c..f3c866419d 100644
--- a/iothub/service/src/Common/Exceptions/ErrorCode.cs
+++ b/iothub/service/src/Common/Exceptions/ErrorCode.cs
@@ -292,6 +292,12 @@ public enum ErrorCode
// Throttling Exception
+ ///
+ /// IoT hub throttling limits have been exceeded for the requested operation.
+ /// For more information, IoT hub quotas and throttling.
+ ///
+ GenericTooManyRequests = 429000,
+
///
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, IoT hub quotas and throttling.
@@ -306,6 +312,24 @@ public enum ErrorCode
///
ThrottleBacklogLimitExceeded = 429002,
+ ///
+ /// IoT hub throttling limits have been exceeded for the requested operation.
+ /// For more information, IoT hub quotas and throttling.
+ ///
+ ThrottlingBacklogTimeout = 429003,
+
+ ///
+ /// IoT hub throttling limits have been exceeded for the requested operation.
+ /// For more information, IoT hub quotas and throttling.
+ ///
+ ThrottlingMaxActiveJobCountExceeded = 429004,
+
+ ///
+ /// IoT hub throttling limits have been exceeded for the requested operation.
+ /// For more information, IoT hub quotas and throttling.
+ ///
+ DeviceThrottlingLimitExceeded = 429005,
+
///
/// IoT hub ran into a server side issue when attempting to throttle.
///
diff --git a/iothub/service/src/Common/Exceptions/IotHubException.cs b/iothub/service/src/Common/Exceptions/IotHubException.cs
index 0ab38bbdf2..a7176cb983 100644
--- a/iothub/service/src/Common/Exceptions/IotHubException.cs
+++ b/iothub/service/src/Common/Exceptions/IotHubException.cs
@@ -157,7 +157,7 @@ internal IotHubException()
///
/// Indicates if the error is transient and should be retried.
///
- public bool IsTransient { get; private set; }
+ public bool IsTransient { get; protected set; }
///
/// The service returned tracking Id associated with this particular error.
diff --git a/iothub/service/src/Common/Exceptions/IotHubThrottledException.cs b/iothub/service/src/Common/Exceptions/IotHubThrottledException.cs
index fadc550e4f..07c436b68e 100644
--- a/iothub/service/src/Common/Exceptions/IotHubThrottledException.cs
+++ b/iothub/service/src/Common/Exceptions/IotHubThrottledException.cs
@@ -18,38 +18,29 @@ public sealed class IotHubThrottledException : IotHubException
{
///
/// Creates an instance of this class with the value of the
- /// maximum allowed count of active requests and marks it as non-transient.
+ /// maximum allowed count of active requests and marks it as transient.
///
/// The maximum allowed count of active requests.
public IotHubThrottledException(int maximumBatchCount)
- : this($"Device Container has exceeded maximum number of allowed active requests: {maximumBatchCount}.")
+ : base($"Device Container has exceeded maximum number of allowed active requests: {maximumBatchCount}.", true)
{
}
///
/// Creates an instance of this class with a specified error message and
- /// a reference to the inner exception that caused this exception, and marks it as non-transient.
+ /// a reference to the inner exception that caused this exception, and marks it as transient.
///
/// The message that describes the error.
/// The exception that is the cause of the current exception.
public IotHubThrottledException(string message, Exception innerException)
- : base(message, innerException)
- {
- }
-
- internal IotHubThrottledException()
- : base()
- {
- }
-
- internal IotHubThrottledException(string message)
- : base(message)
+ : base(message, innerException, true)
{
}
private IotHubThrottledException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
+ IsTransient = true;
}
}
}
diff --git a/iothub/service/src/Common/Exceptions/JobQuotaExceededException.cs b/iothub/service/src/Common/Exceptions/JobQuotaExceededException.cs
index f46e54443d..d87440128b 100644
--- a/iothub/service/src/Common/Exceptions/JobQuotaExceededException.cs
+++ b/iothub/service/src/Common/Exceptions/JobQuotaExceededException.cs
@@ -15,7 +15,7 @@ public sealed class JobQuotaExceededException : IotHubException
private const string DefaultErrorMessage = "Job quota has been exceeded.";
///
- /// Creates an instance of this class with the default error message and marks it as non-transient.
+ /// Creates an instance of this class with the default error message and marks it as transient.
///
public JobQuotaExceededException()
: this(DefaultErrorMessage)
@@ -23,22 +23,25 @@ public JobQuotaExceededException()
}
///
- /// Creates an instance of this class with a specified error message and marks it as non-transient.
+ /// Creates an instance of this class with a specified error message and marks it as transient.
///
/// The message that describes the error.
public JobQuotaExceededException(string message)
- : base(message)
+ : base(message, true)
{
}
internal JobQuotaExceededException(string message, Exception innerException)
: base(message, innerException)
{
+
+ IsTransient = true;
}
private JobQuotaExceededException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
+ IsTransient = true;
}
}
}
diff --git a/iothub/service/src/Common/Exceptions/QuotaExceededException.cs b/iothub/service/src/Common/Exceptions/QuotaExceededException.cs
index a0f9cff48b..e6e80fbbeb 100644
--- a/iothub/service/src/Common/Exceptions/QuotaExceededException.cs
+++ b/iothub/service/src/Common/Exceptions/QuotaExceededException.cs
@@ -22,7 +22,7 @@ public sealed class QuotaExceededException : IotHubException
///
/// The message that describes the error.
public QuotaExceededException(string message)
- : this(message, null)
+ : base(message, true)
{
}
@@ -48,14 +48,10 @@ public QuotaExceededException(string message, Exception innerException)
{
}
- internal QuotaExceededException()
- : base()
- {
- }
-
private QuotaExceededException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
+ IsTransient = true;
}
}
}
diff --git a/iothub/service/src/Common/Exceptions/ServerBusyException.cs b/iothub/service/src/Common/Exceptions/ServerBusyException.cs
index 712da61d00..b4ec3e6ee8 100644
--- a/iothub/service/src/Common/Exceptions/ServerBusyException.cs
+++ b/iothub/service/src/Common/Exceptions/ServerBusyException.cs
@@ -47,11 +47,6 @@ public ServerBusyException(string message, Exception innerException)
{
}
- internal ServerBusyException()
- : base()
- {
- }
-
private ServerBusyException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/iothub/service/src/Common/Exceptions/ThrottlingException.cs b/iothub/service/src/Common/Exceptions/ThrottlingException.cs
index 41b06587c3..49953f88b2 100644
--- a/iothub/service/src/Common/Exceptions/ThrottlingException.cs
+++ b/iothub/service/src/Common/Exceptions/ThrottlingException.cs
@@ -13,33 +13,34 @@ namespace Microsoft.Azure.Devices.Common.Exceptions
public class ThrottlingException : IotHubException
{
///
- /// Creates an instance of with a specified error message and marks it as non-transient.
+ /// Creates an instance of with a specified error message and marks it as transient.
///
/// The message that describes the error.
public ThrottlingException(string message)
- : base(message)
+ : base(message, true)
{
}
///
/// Creates an instance of with a specified , error message
- /// and marks it as non-transient.
+ /// and marks it as transient.
///
/// The associated with the error.
/// The message that describes the error.
public ThrottlingException(ErrorCode code, string message)
: base(code, message)
{
+ IsTransient = true;
}
///
/// Creates an instance of with a specified error message and
- /// a reference to the inner exception that caused this exception, and marks it as non-transient.
+ /// a reference to the inner exception that caused this exception, and marks it as transient.
///
/// The message that describes the error.
/// The exception that is the cause of the current exception.
public ThrottlingException(string message, Exception inner)
- : base(message, inner)
+ : base(message, inner, true)
{
}
@@ -52,11 +53,7 @@ public ThrottlingException(string message, Exception inner)
protected ThrottlingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
- }
-
- internal ThrottlingException()
- : base()
- {
+ IsTransient = true;
}
}
}