Skip to content
Browse files

If the error response doesn't look like an Error object, don't conver…

…t it into one.
  • Loading branch information...
1 parent 3d2a7b3 commit 409300a66e5966077d72e25494bd13f772809aa5 @dfellis dfellis committed Dec 28, 2013
Showing with 22 additions and 1 deletion.
  1. +3 −1 lib/client.js
  2. +19 −0 test/full-stack.js
View
4 lib/client.js
@@ -58,8 +58,10 @@ JSONRPC.prototype.request = function(method, args, callback) {
if(key !== 'message') err[key] = response.error[key];
});
callback(err);
- } else {
+ } else if (typeof response.error === 'string') {
callback(new Error(response.error));
+ } else {
+ callback(response.error);
}
} else {
callback(undefined, response.result);
View
19 test/full-stack.js
@@ -51,6 +51,25 @@ exports.failureTcp = function(test) {
});
};
+exports.objectFailureTcp = function(test) {
+ test.expect(4);
+ var server = new Server(new ServerTcp(44444), {
+ failure: function(arg, callback) { callback({ foo: "I have no idea what I'm doing." }); }
+ });
+ var client = new Client(new ClientTcp('localhost', 44444), {}, function(c) {
+ c.failure('foo', function(err) {
+ test.ok(!!err, 'error exists');
+ test.equal(err.foo, "I have no idea what I'm doing.", 'error message transmitted successfully.');
+ c.shutdown(function() {
+ server.shutdown(test.done.bind(test));
+ });
+ });
+ });
+ client.transport.on('message', function() {
+ test.ok('received a message'); // should happen twice
+ });
+};
+
exports.sweepedRequest = function(test) {
test.expect(2);
var client = new Client(new ClientTcp('localhost', 44444));

0 comments on commit 409300a

Please sign in to comment.
Something went wrong with that request. Please try again.