Azure / azure-iot-hub-node

Azure IoT Hub Data Plane Node SDK
MIT License
1 stars 7 forks source link

Distinguishing 404 Errors in azure-iothub Library #36

Open aenp opened 8 months ago

aenp commented 8 months ago

Hello,

I'm encountering challenges in distinguishing between different 404 errors returned by the azure-iothub library after sending a direct method. The 404 status code doesn't provide specific details, making it hard to differentiate errors like GatewayTimeout, DeviceNotFound, or DeviceNotOnline.

Could you please provide guidance on how to distinguish these specific error types within the 404 responses? Any assistance or insights on handling these errors effectively would be greatly appreciated.

lpikora commented 3 months ago

More specifically reposne body of error from IoTHub server is like:

  responseBody: `{"Message":"{\\"errorCode\\":404103,\\"trackingId\\":\\"f021b8452fa549dd890936sdf978a6f01-TimeStamp:05/29/2024 08:16:08\\",\\"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-05-29T08:16:08.5490632Z\\"}","ExceptionMessage":""}`

code property is missing but there is a errorCode but in node library a string 'DeviceNotFound' and code property is used to check for type of this error: https://github.com/Azure/azure-iot-hub-node/blob/63399a9632d0ad68e6fbc2cbad4e9689723b6396/src/common-http/rest_api_client.ts#L319

There should be check for that number or IoTHub should respond with a string.