From 63e07638f8bb7ae0131e84231200c70a15631cad Mon Sep 17 00:00:00 2001 From: Samuel Matis Date: Fri, 7 Feb 2014 12:56:45 +0100 Subject: [PATCH] Added error handling --- server/server.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/server.js b/server/server.js index de8ed8f..3b9f547 100644 --- a/server/server.js +++ b/server/server.js @@ -63,8 +63,8 @@ var sendRequest = function(ipAddress, type, action, command, options) { }); req.on('error', function(e) { - console.log('error: ' + e.message); - console.log(e); + console.log('ERROR: ' + e); + return false; }); req.write(body); @@ -72,8 +72,11 @@ var sendRequest = function(ipAddress, type, action, command, options) { }; vieraControl.post('/tv/:ip/action', function(req, res) { - sendRequest(req.params.ip, 'command', 'X_SendKey', ''+req.body.action+''); - res.end(); + if(sendRequest(req.params.ip, 'command', 'X_SendKey', ''+req.body.action+'')) { + res.end(); + } else { + res.send({"error": "internal error"}); + } }); vieraControl.get('/tv/:ip/volume', function(req, res) {