Skip to content

Commit

Permalink
Update service error codes (#3315)
Browse files Browse the repository at this point in the history
* Update service error codes

* Fix transientness of associated exceptions
  • Loading branch information
drwill-ms authored May 2, 2023
1 parent 06d0936 commit abe2b4c
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 48 deletions.
2 changes: 0 additions & 2 deletions e2e/test/iothub/DeviceClientE2eTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public async Task DeviceClient_CloseAsync_CanBeCalledTwice()
finally
{
await testDevice.RemoveDeviceAsync().ConfigureAwait(false);
testDevice.Dispose();
}

}
}
}
5 changes: 3 additions & 2 deletions iothub/device/src/Common/Exceptions/IotHubException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ protected IotHubException(SerializationInfo info, StreamingContext context)
}
}

internal IotHubException(bool isTransient) : base()
internal IotHubException(bool isTransient)
: base()
{
IsTransient = isTransient;
}

/// <summary>
/// Indicates if the error is transient and should be retried.
/// </summary>
public bool IsTransient { get; private set; }
public bool IsTransient { get; protected set; }

/// <summary>
/// The service returned tracking Id associated with this particular error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public sealed class IotHubThrottledException : IotHubException
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public IotHubThrottledException() : base(isTransient: true)
public IotHubThrottledException()
: base(isTransient: true)
{
}

Expand Down Expand Up @@ -65,6 +66,7 @@ public IotHubThrottledException(string message, Exception innerException)
private IotHubThrottledException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
IsTransient = true;
}
}
}
5 changes: 3 additions & 2 deletions iothub/device/src/Common/Exceptions/QuotaExceededException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public sealed class QuotaExceededException : IotHubException
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public QuotaExceededException() : base(isTransient: true)
public QuotaExceededException()
: base(isTransient: true)
{
}

Expand All @@ -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.</param>
public QuotaExceededException(string message)
: this(message, null)
: base(message, true)
{
}

Expand Down
6 changes: 4 additions & 2 deletions iothub/device/src/Common/Exceptions/ServerBusyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public sealed class ServerBusyException : IotHubException
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public ServerBusyException() : base(isTransient: true)
public ServerBusyException()
: base(isTransient: true)
{
}

Expand All @@ -29,7 +30,7 @@ public ServerBusyException() : base(isTransient: true)
/// </summary>
/// <param name="message">The error message.</param>
public ServerBusyException(string message)
: this(message, null)
: base(message, true)
{
}

Expand All @@ -43,6 +44,7 @@ public ServerBusyException(string message, Exception innerException)
private ServerBusyException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
IsTransient = true;
}
}
}
24 changes: 24 additions & 0 deletions iothub/service/src/Common/Exceptions/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ public enum ErrorCode

// Throttling Exception

/// <summary>
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, <see href="https://aka.ms/iothubthrottling">IoT hub quotas and throttling</see>.
/// </summary>
GenericTooManyRequests = 429000,

/// <summary>
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, <see href="https://aka.ms/iothubthrottling">IoT hub quotas and throttling</see>.
Expand All @@ -306,6 +312,24 @@ public enum ErrorCode
/// </summary>
ThrottleBacklogLimitExceeded = 429002,

/// <summary>
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, <see href="https://aka.ms/iothubthrottling">IoT hub quotas and throttling</see>.
/// </summary>
ThrottlingBacklogTimeout = 429003,

/// <summary>
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, <see href="https://aka.ms/iothubthrottling">IoT hub quotas and throttling</see>.
/// </summary>
ThrottlingMaxActiveJobCountExceeded = 429004,

/// <summary>
/// IoT hub throttling limits have been exceeded for the requested operation.
/// For more information, <see href="https://aka.ms/iothubthrottling">IoT hub quotas and throttling</see>.
/// </summary>
DeviceThrottlingLimitExceeded = 429005,

/// <summary>
/// IoT hub ran into a server side issue when attempting to throttle.
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion iothub/service/src/Common/Exceptions/IotHubException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ internal IotHubException()
/// <summary>
/// Indicates if the error is transient and should be retried.
/// </summary>
public bool IsTransient { get; private set; }
public bool IsTransient { get; protected set; }

/// <summary>
/// The service returned tracking Id associated with this particular error.
Expand Down
19 changes: 5 additions & 14 deletions iothub/service/src/Common/Exceptions/IotHubThrottledException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,29 @@ public sealed class IotHubThrottledException : IotHubException
{
/// <summary>
/// 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.
/// </summary>
/// <param name="maximumBatchCount">The maximum allowed count of active requests.</param>
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)
{
}

/// <summary>
/// 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.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,33 @@ public sealed class JobQuotaExceededException : IotHubException
private const string DefaultErrorMessage = "Job quota has been exceeded.";

/// <summary>
/// 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.
/// </summary>
public JobQuotaExceededException()
: this(DefaultErrorMessage)
{
}

/// <summary>
/// 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.
/// </summary>
/// <param name="message">The message that describes the error.</param>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class QuotaExceededException : IotHubException
/// </summary>
/// <param name="message">The message that describes the error.</param>
public QuotaExceededException(string message)
: this(message, null)
: base(message, true)
{
}

Expand All @@ -48,14 +48,10 @@ public QuotaExceededException(string message, Exception innerException)
{
}

internal QuotaExceededException()
: base()
{
}

private QuotaExceededException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
IsTransient = true;
}
}
}
5 changes: 0 additions & 5 deletions iothub/service/src/Common/Exceptions/ServerBusyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ public ServerBusyException(string message, Exception innerException)
{
}

internal ServerBusyException()
: base()
{
}

private ServerBusyException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
17 changes: 7 additions & 10 deletions iothub/service/src/Common/Exceptions/ThrottlingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@ namespace Microsoft.Azure.Devices.Common.Exceptions
public class ThrottlingException : IotHubException
{
/// <summary>
/// Creates an instance of <see cref="ThrottlingException"/> with a specified error message and marks it as non-transient.
/// Creates an instance of <see cref="ThrottlingException"/> with a specified error message and marks it as transient.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ThrottlingException(string message)
: base(message)
: base(message, true)
{
}

/// <summary>
/// Creates an instance of <see cref="ThrottlingException"/> with a specified <see cref="ErrorCode"/>, error message
/// and marks it as non-transient.
/// and marks it as transient.
/// </summary>
/// <param name="code">The <see cref="ErrorCode"/> associated with the error.</param>
/// <param name="message">The message that describes the error.</param>
public ThrottlingException(ErrorCode code, string message)
: base(code, message)
{
IsTransient = true;
}

/// <summary>
/// Creates an instance of <see cref="ThrottlingException"/> 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.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="inner">The exception that is the cause of the current exception.</param>
public ThrottlingException(string message, Exception inner)
: base(message, inner)
: base(message, inner, true)
{
}

Expand All @@ -52,11 +53,7 @@ public ThrottlingException(string message, Exception inner)
protected ThrottlingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

internal ThrottlingException()
: base()
{
IsTransient = true;
}
}
}

0 comments on commit abe2b4c

Please sign in to comment.