js-adapters/router.js in rhoconnect-4.0.0.beta.12 vs js-adapters/router.js in rhoconnect-4.0.0.beta.24

- old
+ new

@@ -1,9 +1,9 @@ var Response = require('./response'); var Request = require('./request'); -var router = function(json){ +var router = function(json,send){ switch(json['route']){ case 'request': try { var request = new Request(); var resp1 = new Response(); @@ -21,37 +21,39 @@ model_dir = process.cwd() + "/spec/apps/rhotestapp/models/js/"; } else{ model_dir = process.cwd() + "/models/js/"; } - //console.error("path is: ******* " + model_dir + json['klss'] + '.js'); var mod = require(model_dir + json['klss'] + '.js'); mod[json['function']](resp1); } else{ - //console.error("reg routes are: " + registeredRoutes[json['url']]); registeredRoutes[json['url']](request,resp1); } break; } catch(e){ - console.error("Node.js error caught: "+ e); - console.error("Backtrace: " + e.stack); - resp1.exception = {"error": e}; + console.error(e.stack || e.toString()); + resp1.exception = {"error": {"error_type": e.name, "message": e.message, "stacktrace": e.stack} }; resp1.send(null); } break; case 'response': - //console.error("result callback is: " + json['callback']) - var cback = json['callback']; - json['callback'] = undefined; - var resp2 = new Response(); - resp2.header = {'request_id':json['request_id'],'route':'response'}; - resp2.result = json['result']; + try { + var cback = json['callback']; + json['callback'] = undefined; + var resp2 = new Response(); + resp2.header = {'request_id':json['request_id'],'route':'response'}; + resp2.result = json['result']; - rhoconnectCallbacks[cback](resp2); - delete rhoconnectCallbacks[cback]; + rhoconnectCallbacks[cback](resp2); + delete rhoconnectCallbacks[cback]; + } catch(e) { + console.error(e.stack || e.toString()); + resp2.exception = {"error": {"error_type": e.name, "message": e.message, "stacktrace": e.stack} }; + resp2.send(null); + } break; case 'deregister': var br = require('ballroom'); br.exitNodejs(); break; \ No newline at end of file