From 411aff6f5f8e39179c989d128635ac36728a2f40 Mon Sep 17 00:00:00 2001 From: Bill Casarin Date: Sun, 28 Aug 2011 10:34:18 -0400 Subject: [PATCH] Fixed issue where json-rpc would ignore some errors --- lib/jsonrpc.js | 6 ++++-- package.json | 2 +- test.js | 6 +++--- test/api.js | 6 +++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/jsonrpc.js b/lib/jsonrpc.js index 5949459..6db9686 100644 --- a/lib/jsonrpc.js +++ b/lib/jsonrpc.js @@ -1,6 +1,5 @@ var sys = require('sys'); var http = require('http'); - var METHOD_NOT_ALLOWED = "Method Not Allowed\n"; var INVALID_REQUEST = "Invalid Request\n"; @@ -61,7 +60,10 @@ var Client = function(port, host, user, password) { // emitSuccess or emitError on the promise. response.on('end', function() { var decoded = JSON.parse(buffer); - if(decoded.hasOwnProperty('result')) { + if(decoded.hasOwnProperty('error') && decoded.error != null) { + if (errback) + errback(decoded.error) + } else if(decoded.hasOwnProperty('result')) { if (callback) callback(decoded.result); } diff --git a/package.json b/package.json index f63c463..6eb5e53 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bitcoin", "description": "Communicate with bitcoind via JSON-RPC", - "version": "1.0.1", + "version": "1.1.0", "main": "./lib/bitcoin", "keywords": [ "bitcoin", diff --git a/test.js b/test.js index f765e3a..9e24a51 100644 --- a/test.js +++ b/test.js @@ -2,13 +2,13 @@ var bitcoin = require('./lib/bitcoin'); var client = new bitcoin.Client('localhost', 8332, 'jb55', 'thisisthepassword'); -doCmd('getWork'); - function doCmd(cmd) { - client[cmd](function(data) { + client[cmd](function(err, data) { console.log(cmd); console.log(data); + console.log("err: ", err); console.log(''); }); } +doCmd('getWork'); diff --git a/test/api.js b/test/api.js index ae0e089..4c9c1cd 100644 --- a/test/api.js +++ b/test/api.js @@ -32,7 +32,7 @@ vows.describe('api').addBatch({ client.getAccountAddress(test.account, this.callback); }, 'is valid': function(address){ - assert.ok(address, "Update test variables with a valid address?"); + assert.ok(address); }, 'after getting the account name again': { topic: function(address, client) { @@ -89,6 +89,10 @@ vows.describe('api').addBatch({ topic: function(client) { client.help(this.callback); }, 'should not be empty': notEmpty, }, + 'getWork': { + topic: function(client) { client.getWork(this.callback); }, + 'should not be empty': notEmpty, + }, 'getTransaction': { topic: "TODO: get valid transaction", 'should not be empty': notEmpty,