Catch SyntaxError exception and log nice error message

This commit is contained in:
grz0
2013-12-17 18:33:05 +01:00
parent 6e416550db
commit f23748c29d
+7 -2
View File
@@ -13,7 +13,7 @@ exports.registerNode = function (configFile) {
if (data) {
postRequest(data);
} else {
logger.error("No data found in the node configuration file to send to the grid");
logger.error("No data found in the node configuration file to send to the grid");
}
});
};
@@ -31,7 +31,12 @@ function registerToGrid(options_post, jsonObject) {
function postRequest(data) {
//parse json to get hub host and port
var jsonObject = JSON.parse(data);
var jsonObject;
try {
jsonObject = JSON.parse(data);
} catch(e) {
return logger.error("Syntax error in node configuration file: " + e.message);
}
// prepare the header
var post_headers = {
'Content-Type' : 'application/json'