Try/catch in ECMA 11 for sendHttpGetRequest timeout?

ECMA 11 on OH4M3

Is it possible to catch the timeout exception in Javascript for a sendHttpGetRequest? This did not work:

  try {
    var TstatStatusResponse = actions.HTTP.sendHttpGetRequest("", 20000);
  } catch (error) {
    console.warn("Request to thermostat failed: " + error);

Got this in the log:

[ERROR] [enhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: Connect Timeout

I would like to handle this more gracefully as these timeouts are a fact of life for the device, so they pollute the log file. I know that there will be several per day which my rules can handle. I suppose I could use a log file filter, but better to stop them at the source if possible. thanks

I don’t think it’s possible in any language. The timeout is caught and reported in the underlying code. But I think the action returns null if it timed out. But it should be easy enough to test.

If this is just about the logging, as you surmise, a filter is your best bet.

1 Like