Skip to content

Commit

Permalink
Add DeviceNotOnline to error codes (#3450)
Browse files Browse the repository at this point in the history
Co-authored-by: Preben Huybrechts <[email protected]>
  • Loading branch information
timtay-microsoft and pregress authored Apr 9, 2024
1 parent 2a97dd0 commit c673d37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions iothub/service/src/Common/Exceptions/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ public enum ErrorCode
[EditorBrowsable(EditorBrowsableState.Never)]
JobNotFound = 404002,

/// <summary>
/// The operation failed because the device is offline or the direct method callback isn't registered.
/// <para>
/// For more information, see <see href="https://aka.ms/iothub404103">404103 Device not online</see>.
/// </para>
/// </summary>
DeviceNotOnline = 404103,

/// <summary>
/// The error is internal to IoT hub and is likely transient.
/// <para>
Expand Down
19 changes: 19 additions & 0 deletions iothub/service/tests/ExceptionHandlingHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ public async Task GetExceptionCodeAsync_ContentAndHeadersMatch_ValidErrorCode()
Assert.AreEqual(ErrorCode.DeviceNotFound, errorCode);
}

[TestMethod]
public async Task GetExceptionCodeAsync_ContentAndHeadersMatch_ValidErrorCode_DeviceNotOnline()
{
// arrange
var httpResponseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
var exceptionResult = new IoTHubExceptionResult
{
Message = "{\"errorCode\":404103}"
};
httpResponseMessage.Content = new StringContent(JsonConvert.SerializeObject(exceptionResult));
httpResponseMessage.Headers.Add(CommonConstants.HttpErrorCodeName, "DeviceNotOnline");

// act
ErrorCode errorCode = await ExceptionHandlingHelper.GetExceptionCodeAsync(httpResponseMessage);

// assert
Assert.AreEqual(ErrorCode.DeviceNotOnline, errorCode);
}

[TestMethod]
public async Task GetExceptionCodeAsync_ContentAndHeadersMisMatch_InvalidErrorCode()
{
Expand Down

0 comments on commit c673d37

Please sign in to comment.