Skip to content

Commit a52cbe7

Browse files
committed
New error handling
1 parent b255e9d commit a52cbe7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/init.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ module.exports = function(apiKey, chain) {
5656
}
5757

5858
if (data.error) {
59-
return reject(data.error.message);
59+
return reject(new Error(data.error));
6060
}
61-
6261
resolve(data);
6362
}).catch(function(error) {
64-
return reject(error);
63+
return reject(new Error(error));
6564
});
6665
});
6766
}
@@ -544,7 +543,7 @@ module.exports = function(apiKey, chain) {
544543
let action = 'balance';
545544
const tag = 'latest';
546545

547-
if (typeof address != 'string' && address.length) {
546+
if (typeof address !== 'string' && address && address.length) {
548547
address = address.join(',');
549548
action = 'balancemulti';
550549
}

test/error-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const assert = require('chai').assert;
3+
const init = require('../.').init;
4+
describe('balance', function() {
5+
6+
it('no param sends a error', function(done){
7+
var api = init();
8+
var balance = api.account.balance();
9+
balance.catch(function(err){
10+
assert.ok(err);
11+
done();
12+
});
13+
});
14+
});

0 commit comments

Comments
 (0)