aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

How to handle error when calling awsIot.thingShadow#register() #274

Closed michaelwittig closed 4 years ago

michaelwittig commented 5 years ago

Hi,

I wonder how I have to handle an error during awsIot.thingShadow#register().

const thingShadow = awsIot.thingShadow({
  keyPath: '...',
  certPath: '...',
  caPath: '...',
  clientId: 'clientid',
  host: 'host'
});
thingShadow.register('thingname', {}, function(err) {
  if (err) {
    // what should I do?
  } else {
    // ok, great
  }
});

It looks like, calling register again is not a good idea (no callback ever called https://github.com/aws/aws-iot-device-sdk-js/blob/master/thing/index.js#L616)

As far as I understand, even if I get an error during register(), the subscriptions will be made as soon as the connection is alive?

The documentation mentions "Applications should wait until shadow registration is complete before performing update/get/delete operations.". How can I know that the registration is complete if I get an error?

jiangshunke commented 4 years ago

@michaelwittig It seems like you can use get to detect if the opClientToken is null

jmklix commented 4 years ago

@michaelwittig where you able to find a way to handle the error? If so was it by checking if opClientToken is null?

github-actions[bot] commented 4 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.