Miguel Morujão
Miguel Morujão

Reputation: 1161

Meteor - How to handle external API connection errors?

I'm using a few external API's (some in timers, every minute or so) and sometimes I get some connection errors because of network problems or because the external systems are down for some reason. When I get this errors, the app restarts, and if the error persists the app continues restarting.

enter image description here

Any ideas on how can I ignore the connection error and keep the app running?

Code Example:

  try {
      var req = https.request(options, callback);
      req.write(JSON.stringify(params));
      req.end();
    } catch (e) {
      throw e;
    }

Upvotes: 0

Views: 79

Answers (1)

dzm
dzm

Reputation: 23544

Based on your code example. You're doing throw e inside your try catch. Essentially, you're catching an error and then throwing the error. Just do console.error(err) or however you want to handle that error, without throwing. This is what will cause your instance to stop.

Upvotes: 3

Related Questions