From 92329d7ea4a200f54b047ee22a8b4de6ddf71035 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 30 Sep 2016 03:06:08 -0400 Subject: [PATCH] better error handling --- wsclient.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wsclient.js b/wsclient.js index c66d4b9..72a55f4 100644 --- a/wsclient.js +++ b/wsclient.js @@ -69,7 +69,7 @@ return; var handlers = { onmessage: function (opts) { var cid = addrToId(opts); - console.log('[wsclient] onMessage:', cid); + console.log('[wsclient] onMessage:', cid, opts); var service = opts.service; var port = services[service]; var lclient; @@ -89,7 +89,11 @@ return; } function endWithError() { - wstunneler.send(pack(opts, null, 'error'), { binary: true }); + try { + wstunneler.send(pack(opts, null, 'error'), { binary: true }); + } catch(e) { + // ignore + } } if (localclients[cid]) { @@ -132,12 +136,20 @@ return; console.error("[error] local '" + opts.service + "' '" + cid + "'"); console.error(err); delete localclients[cid]; - wstunneler.send(pack(opts, null, 'error'), { binary: true }); + try { + wstunneler.send(pack(opts, null, 'error'), { binary: true }); + } catch(e) { + // ignore + } }); lclient.on('end', function () { console.log("[end] local '" + opts.service + "' '" + cid + "'"); delete localclients[cid]; - wstunneler.send(pack(opts, null, 'end'), { binary: true }); + try { + wstunneler.send(pack(opts, null, 'end'), { binary: true }); + } catch(e) { + // ignore + } }); } , onend: function (opts) {