diff --git a/lib/msgpack-rpc.js b/lib/msgpack-rpc.js index 12612f3..2374da7 100644 --- a/lib/msgpack-rpc.js +++ b/lib/msgpack-rpc.js @@ -18,6 +18,11 @@ RPCResponse.prototype.result = function(args) { } RPCResponse.prototype.error = function(error) { + if (error instanceof Error) { + // add 'msg' because 'message' property is not enumerable + // and will not be part of an msgpack encoded message. + error.msg = error.message; + } this.stream.respond(this.seqid, error, null); } @@ -94,7 +99,15 @@ MsgpackRPCStream.prototype.invokeHandler = function(method, params) { if(this.handler[method]) { this.handler[method].apply(this.handler, params); } else { - response.error(new Error("unknown method")); + error(new Error("unknown method")); + } + } else { + error(new Error("no handler")); + } + function error(err) { + var response = params.pop(); + if (response && response instanceof RPCResponse) { + response.error(err); } } } @@ -148,6 +161,10 @@ MsgpackRPCStream.prototype.close = function() { this.stream.end(); } +MsgpackRPCStream.prototype.setHandler = function(handler) { + this.handler = handler; +} + exports.createClient = function(port, hostname,cb) { var s = new MsgpackRPCStream(new net.createConnection(port, hostname)); if(typeof hostname == 'function') s.on('ready', hostname); diff --git a/package.json b/package.json index 6e2fff1..08bec05 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - 'name' : 'msgpack-rpc', - 'version' : '0.0.1', - 'description' : 'node-msgpack-rpc is an implementation of the Msgpack-RPC protocol specification for node.js', - 'homepage' : 'https://github.com/bpot/node-msgpack-rpc', - 'main' : './lib/msgpack-rpc', - 'repository' : { + "name" : "msgpack-rpc", + "version" : "0.0.1", + "description" : "node-msgpack-rpc is an implementation of the Msgpack-RPC protocol specification for node.js", + "homepage" : "https://github.com/bpot/node-msgpack-rpc", + "main" : "./lib/msgpack-rpc", + "repository" : { "type" : "git", "url" : "https://github.com/bpot/node-msgpack-rpc.git" }, - 'directories': { + "directories": { "lib": "lib" } }