Error handling in Cloudantplus node

I'm trying to fix a problem with the Cloudantplus node where it errors and stops NR if it can't connect to the Cloudant database (incorrect URL or credentials). In the node logic I have:

node.on("input", (msg, send, done) => {
      node.debug("Connecting...");
      base
      .connecWithRetry(node, node.cloudantConfig, 1)
      .then((service) => {node.debug("Connected..."); handleMessage(service, node, msg, send, done)})
      .catch((err) => {node.debug("Error connecting..."); done(err)})
    })

base.connecWithRetry returns a promise but if there is an error in the connection then it never seems to get to the catch clause, it just stops NR. Baffled! It works just fine if it can connect to Cloudant.

The code for connecWithRetry is here: node-red-contrib-cloudantplus/cloudantbase.js at master · hammoaj/node-red-contrib-cloudantplus · GitHub

I'm probably missing something really stupid, but I can't see it. Can't work out why the error isn't being trapped.

Thanks

OK - worked out what the issue is, just not sure how to fix it. The function tries to connect to the database and if it fails, it sets a timer to call the function again after a period of time up to a maximum number of tries. Of course, by doing it this way, it's losing the chain of promises, so by the time it returns to the original calling node it is indeed untrapped. Tested this by setting the maximum tries to 1 and it behaves properly.

Is there a standard pattern to doing retries with delays using promises that anyone can share with me?

Think this is fixed in the latest version of the node

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.