Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/msgpack-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}