jimmywarting / wemo-client

JavaScript client library for controlling and subscribing to Wemo Devices
MIT License
132 stars 40 forks source link

Connection timeout is not handled #44

Closed BasKiers closed 8 years ago

BasKiers commented 8 years ago

Hi,

Im using your library but after a certain amount of time (1-2 days or something) I get an ETIMEDOUT exception. Is this something you can handle in your library and if not where should I handle this exception and establish a new connection?

Regards, Bas

Stack trace:

Error: connect ETIMEDOUT 192.168.1.61:49153 at Object.exports._errnoException (util.js:907:11) at exports._exceptionWithHostPort (util.js:930:20) at TCPConnectWrap.afterConnect as oncomplete

timonreinhard commented 8 years ago

Hi Bas,

thanks for reporting this issue. This should be definitely handled by the client indeed. Can you provide the full stack trace and log output (preferably when running with DEBUG=wemo-client)?

timonreinhard commented 8 years ago

I just verified your issue. The wemo-client emits an error event in the given case, which is correct. You need however to bind to this event as node.js would otherwise terminate with Unhandled 'error' event. This is by design as you'll want to handle those errors (e.g. device went offline) in your app and wait for the failing device to reappear via the discovery.

See examples/maker.js#19 on how to listen for client errors. When a listener is added, it won't crash anymore.