Fixed issue where json-rpc would ignore some errors
This commit is contained in:
parent
d3a8d7fbb7
commit
411aff6f5f
@ -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);
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
6
test.js
6
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');
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user