From 75f538fa16f7b2ea85b7dc1781042b9ae251a5ea Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 4 Nov 2018 14:28:07 -0700 Subject: [PATCH] minor cleanup, throw on previously unchecked error --- bin/telebit-remote.js | 6 +++--- lib/rc/index.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bin/telebit-remote.js b/bin/telebit-remote.js index 3ef5ebc..16e1a3b 100755 --- a/bin/telebit-remote.js +++ b/bin/telebit-remote.js @@ -306,8 +306,8 @@ var RC; function parseConfig(err, text) { function handleConfig(err, config) { - //console.log('CONFIG'); - //console.log(config); + if (err) { throw err; } + state.config = config; var verstrd = [ pkg.name + ' daemon v' + state.config.version ]; if (state.config.version && state.config.version !== pkg.version) { @@ -652,7 +652,7 @@ function parseConfig(err, text) { }); } - RC.request({ service: 'config', method: 'GET' }, handleRemoteRequest('config', handleConfig)); + RC.request({ service: 'config', method: 'GET' }, handleConfig); } var parsers = { diff --git a/lib/rc/index.js b/lib/rc/index.js index fd6da53..aa1f3d0 100644 --- a/lib/rc/index.js +++ b/lib/rc/index.js @@ -39,15 +39,18 @@ module.exports.create = function (state) { var err; if (200 !== resp.statusCode) { - err = new Error(body || ('get' + service + ' failed')); + err = new Error(body || ('get ' + service + ' failed')); err.statusCode = resp.statusCode; err.code = "E_REQUEST"; } - try { - body = JSON.parse(body); - } catch(e) { - // ignore + if (body) { + try { + body = JSON.parse(body); + } catch(e) { + console.error('Error:', err); + // ignore + } } fn(err, body);