diff --git a/rpc.js b/rpc.js index a4821524b..410e5f22b 100644 --- a/rpc.js +++ b/rpc.js @@ -1057,11 +1057,9 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) } }; - var rpc = function ( - ctx /*:{ store: Object }*/, - data /*:Array>*/, - respond /*:(?string, ?Array)=>void*/) - { + var rpc0 = function (ctx, data, respond) { + if (!Env.msgStore) { Env.msgStore = ctx.store; } + if (!Array.isArray(data)) { return void respond('INVALID_ARG_FORMAT'); } @@ -1140,8 +1138,6 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) Respond('E_ACCESS_DENIED'); }; - if (!Env.msgStore) { Env.msgStore = ctx.store; } - var handleMessage = function (privileged) { if (config.logRPC) { console.log(msg[0]); } switch (msg[0]) { @@ -1272,6 +1268,19 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) handleMessage(session.privilege); }; + var rpc = function ( + ctx /*:{ store: Object }*/, + data /*:Array>*/, + respond /*:(?string, ?Array)=>void*/) + { + try { + return rpc0(ctx, data, respond); + } catch (e) { + console.log("Error from RPC with data " + JSON.stringify(data)); + console.log(e.stack); + } + }; + var updateLimitDaily = function () { updateLimits(config, undefined, function (e) { if (e) {