From 7fc5ca5f4d009d8a64104b640f03944b43200bf7 Mon Sep 17 00:00:00 2001 From: Andrew Krespanis Date: Wed, 18 Feb 2015 08:14:41 +1100 Subject: [PATCH] command observers log commands which fail to execute correctly --- lib/endpoint.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/endpoint.js b/lib/endpoint.js index 02f5454..723fd9d 100644 --- a/lib/endpoint.js +++ b/lib/endpoint.js @@ -58,7 +58,7 @@ Endpoint.prototype.write = function(value) { catch(e => { log.error({ 'source': this.toString(), - 'message': 'Write command failed', + 'message': 'Write failed', 'data': value }); reject(new Error('Hardware failure')); @@ -76,7 +76,7 @@ Endpoint.prototype.read = function() { catch(e => { log.error({ 'source': this.toString(), - 'message': 'Read command failed', + 'message': 'Read failed', 'data': null }); reject(new Error('Hardware failure')); @@ -92,9 +92,23 @@ Endpoint.prototype.createCommandObserver = function() { } if (command.instruction.type === 'write') { - this.write(command.instruction.value); + this.write(command.instruction.value). + catch(e => { + log.error({ + 'source': 'command:' + this, + 'message': 'Command failed', + 'data': command + }); + }); } else if (command.instruction.type === 'read') { - this.read(); + this.read(). + catch(e => { + log.error({ + 'source': 'command:' + this, + 'message': 'Command failed', + 'data': command + }); + }); } } );