DeviceNotFoundException results in InvalidErrorCode (404103)
pregress opened this issue · 2 comments
pregress commented
Context
- OS, version, SKU and CPU architecture used: Windows 11 Desktop x64 OS build: 22621.3155
- Application's .NET Target Framework : .NET Sdk: 8.0.101
- Device: Laptop
- SDK version used: Azure.Identity 1.10.4, Microsoft.Azure.Devices.Client 1.42.2n Microsoft.Azure.Devices 1.39.1
Description of the issue
https://github.com/Azure/azure-iot-sdk-csharp/blob/main/iothub/service/src/Common/Exceptions/ErrorCode.cs should contain a value for 404103 DeviceOffline
When invoking a direct method on an offline device. A device not found is thrown. OK
The exception.ErrorCode is InvalidErrorCode.
Whilst the json contains: errorCode: 404103
{"Message":"{\"errorCode\":404103,\"trackingId\":\"aa761f96e9174d0e849c96a8b2e10a8c-TimeStamp:03/14/2024 09:54:49\",\"message\":\"The operation failed because the requested device isn't online or hasn't registered the direct method callback. To learn more, see https://aka.ms/iothub404103\",\"info\":{\"timeout\":\"00:00:00\"},\"timestampUtc\":\"2024-03-14T09:54:49.6536567Z\"}","ExceptionMessage":""}
Code sample exhibiting the issue
try
{
var credential = new AzureCliCredential();
var serviceClient = ServiceClient.Create($"redacted-hostname.azure-devices.net", credential);
await serviceClient.InvokeDeviceMethodAsync("YourDevice", new CloudToDeviceMethod("YourDirectMethod", TimeSpan.FromSeconds(10)));
}
catch (DeviceNotFoundException ex)
{
Console.WriteLine("Offline? " + ex.Code);
}
Console log of the issue
Offline? InvalidErrorCode