From 58f8d09775f81e52439377f352ef2cf1e9bd5d78 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Fri, 20 Oct 2017 21:45:17 -0400 Subject: [PATCH] Try catch the connection --- lib/blootstrap/index.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/blootstrap/index.js b/lib/blootstrap/index.js index f015ff7..1e2c40f 100644 --- a/lib/blootstrap/index.js +++ b/lib/blootstrap/index.js @@ -11,25 +11,31 @@ function capitalize (s) { class Blootstrap { constructor () { this._onData = () => {} - ipc.connectTo('blootstrap_ble', () => { - ipc.of.blootstrap_ble.on('connect', () => { - log.info('connect', `Connected to the blootstrap_ble service`) + try { + ipc.connectTo('blootstrap_ble', () => { + ipc.of.blootstrap_ble.on('connect', () => { + log.info('connect', `Connected to the blootstrap_ble service`) + }) + ipc.of.blootstrap_ble.on('data', data => { + const str = data.toString() + log.info('data', str) + this._onData(str) + }) + ipc.of.blootstrap_ble.on('disconnect', () => { + log.info('disconnect', `Disconnected from the blootstrap_ble service`) + }) + ipc.of.blootstrap_ble.on('error', (err) => { + if (err.code === 'EACCES') { + log.warn('ble', `Cannot access ipc`) + } else { + log.error('ble', { error : err }) + } + }) }) - ipc.of.blootstrap_ble.on('data', data => { - const str = data.toString() - log.info('data', str) - this._onData(str) - }) - ipc.of.blootstrap_ble.on('disconnect', () => { - log.info('disconnect', `Disconnected from the blootstrap_ble service`) - }) - ipc.of.blootstrap_ble.on('error', (err) => { - if (err.code === 'EACCES') { - log.warn('error', `Cannot access ipc`) - } - }) - }) + } catch (e) { + log.error('connectTo', { error : e }) + } } /** * Binds functions to events that are triggered by BLE messages