Skip to content

Commit c673d37

Browse files
Add DeviceNotOnline to error codes (#3450)
Co-authored-by: Preben Huybrechts <preben.huybrechts@niko.eu>
1 parent 2a97dd0 commit c673d37

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

iothub/service/src/Common/Exceptions/ErrorCode.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ public enum ErrorCode
205205
[EditorBrowsable(EditorBrowsableState.Never)]
206206
JobNotFound = 404002,
207207

208+
/// <summary>
209+
/// The operation failed because the device is offline or the direct method callback isn't registered.
210+
/// <para>
211+
/// For more information, see <see href="https://aka.ms/iothub404103">404103 Device not online</see>.
212+
/// </para>
213+
/// </summary>
214+
DeviceNotOnline = 404103,
215+
208216
/// <summary>
209217
/// The error is internal to IoT hub and is likely transient.
210218
/// <para>

iothub/service/tests/ExceptionHandlingHelperTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ public async Task GetExceptionCodeAsync_ContentAndHeadersMatch_ValidErrorCode()
3333
Assert.AreEqual(ErrorCode.DeviceNotFound, errorCode);
3434
}
3535

36+
[TestMethod]
37+
public async Task GetExceptionCodeAsync_ContentAndHeadersMatch_ValidErrorCode_DeviceNotOnline()
38+
{
39+
// arrange
40+
var httpResponseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
41+
var exceptionResult = new IoTHubExceptionResult
42+
{
43+
Message = "{\"errorCode\":404103}"
44+
};
45+
httpResponseMessage.Content = new StringContent(JsonConvert.SerializeObject(exceptionResult));
46+
httpResponseMessage.Headers.Add(CommonConstants.HttpErrorCodeName, "DeviceNotOnline");
47+
48+
// act
49+
ErrorCode errorCode = await ExceptionHandlingHelper.GetExceptionCodeAsync(httpResponseMessage);
50+
51+
// assert
52+
Assert.AreEqual(ErrorCode.DeviceNotOnline, errorCode);
53+
}
54+
3655
[TestMethod]
3756
public async Task GetExceptionCodeAsync_ContentAndHeadersMisMatch_InvalidErrorCode()
3857
{

0 commit comments

Comments
 (0)