fblackburn1 / node-red-contrib-hubitat

MIT License
18 stars 4 forks source link

When hubitat api is unavailable, node-red crashes #149

Open robacarp opened 1 year ago

robacarp commented 1 year ago

This morning I upgraded hubitat at the same time as node-red and the palette dependencies. Hubitat takes a while to reboot, but node-red doesn't. I observed the following error message in the node-red log while it was failing to boot:

Unable to initialize device: invalid json response body at http://172.16.0.5/apps/api/14/devices/*?access_token=[...] reason: Unexpected token < in JSON at position 0

The hubitat server is likely responding with the html for the boot-time message rather than a compliant json response, which is failing to parse as JSON.

fblackburn1 commented 1 year ago

Can you confirm that all device node was in error? (e.g. Unable to initialize device) I guess that after redeploying everything was ok?

I don't really know how to fix it properly, because there is not only at the boot time that hub can respond with HTML pages. In fact, all errors are formatted as HTML (ex: When maker-api cannot handle request for whatever reason (overload, etc..)) I could do some retry loop or html parsing, but it would add complexity or flakiness on the initialization process

robacarp commented 1 year ago

I believe so, yes. The error is transient, so it's not straightforward to trace out. I'd have to build and deploy a web server to the network that responds (in)correctly to verify.

The situation you could get yourself in which would really be frustrating is something like this:

Which is admittedly a deep cut edge case, but it would be really frustrating if I lost my node-red config in that way.

In my case, the solution to the problem was simply just "wait 90s and let hubitat finish booting," which is just fine.