Skip to content

Commit

Permalink
Added error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmatis committed Feb 7, 2014
1 parent 193c088 commit 63e0763
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ 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);
req.end();
};

vieraControl.post('/tv/:ip/action', function(req, res) {
sendRequest(req.params.ip, 'command', 'X_SendKey', '<X_KeyEvent>'+req.body.action+'</X_KeyEvent>');
res.end();
if(sendRequest(req.params.ip, 'command', 'X_SendKey', '<X_KeyEvent>'+req.body.action+'</X_KeyEvent>')) {
res.end();
} else {
res.send({"error": "internal error"});
}
});

vieraControl.get('/tv/:ip/volume', function(req, res) {
Expand Down

0 comments on commit 63e0763

Please sign in to comment.