Browse Source

Merge pull request #312 from isocolsky/improve_errors

Improve error messages
activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
9b7b978d28
  1. 4
      lib/errors/errordefinitions.js
  2. 18
      lib/server.js
  3. 12
      test/integration/server.js

4
lib/errors/errordefinitions.js

@ -21,11 +21,13 @@ var errors = {
TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time', TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time',
TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime', TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime',
TX_NOT_ACCEPTED: 'The transaction proposal is not accepted', TX_NOT_ACCEPTED: 'The transaction proposal is not accepted',
TX_NOT_FOUND: 'Transaction proposal not found',
TX_NOT_PENDING: 'The transaction proposal is not pending', TX_NOT_PENDING: 'The transaction proposal is not pending',
UPGRADE_NEEDED: 'Client app needs to be upgraded', UPGRADE_NEEDED: 'Client app needs to be upgraded',
WALLET_ALREADY_EXISTS: 'Wallet already exists', WALLET_ALREADY_EXISTS: 'Wallet already exists',
WALLET_FULL: 'Wallet full', WALLET_FULL: 'Wallet full',
WALLET_NOT_COMPLETE: 'Replace only works on complete wallets', WALLET_NOT_COMPLETE: 'Wallet is not complete',
WALLET_NOT_FOUND: 'Wallet not found',
}; };
var errorObjects = _.zipObject(_.map(errors, function(msg, code) { var errorObjects = _.zipObject(_.map(errors, function(msg, code) {

18
lib/server.js

@ -253,7 +253,7 @@ WalletService.prototype.getWallet = function(opts, cb) {
self.storage.fetchWallet(self.walletId, function(err, wallet) { self.storage.fetchWallet(self.walletId, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet) return cb(new ClientError('Wallet not found')); if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
return cb(null, wallet); return cb(null, wallet);
}); });
}; };
@ -285,7 +285,7 @@ WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) {
self.storage.fetchWallet(self.walletId, function(err, wallet) { self.storage.fetchWallet(self.walletId, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet) return cb(new ClientError('Wallet not found')); if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey); var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey);
if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) {
return cb(new ClientError()); return cb(new ClientError());
@ -397,7 +397,7 @@ WalletService.prototype.joinWallet = function(opts, cb) {
self.storage.fetchWallet(opts.walletId, function(err, wallet) { self.storage.fetchWallet(opts.walletId, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet) return cb(new ClientError('Wallet not found')); if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey); var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey);
if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) {
@ -544,8 +544,7 @@ WalletService.prototype.createAddress = function(opts, cb) {
self._runLocked(cb, function(cb) { self._runLocked(cb, function(cb) {
self.getWallet({}, function(err, wallet) { self.getWallet({}, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE);
return cb(new ClientError('Wallet is not complete'));
var address = wallet.createAddress(false); var address = wallet.createAddress(false);
@ -977,8 +976,7 @@ WalletService.prototype.createTx = function(opts, cb) {
self._runLocked(cb, function(cb) { self._runLocked(cb, function(cb) {
self.getWallet({}, function(err, wallet) { self.getWallet({}, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE);
return cb(new ClientError('Wallet is not complete'));
var copayer = wallet.getCopayer(self.copayerId); var copayer = wallet.getCopayer(self.copayerId);
var hash; var hash;
@ -1087,7 +1085,7 @@ WalletService.prototype.getTx = function(opts, cb) {
self.storage.fetchTx(self.walletId, opts.txProposalId, function(err, txp) { self.storage.fetchTx(self.walletId, opts.txProposalId, function(err, txp) {
if (err) return cb(err); if (err) return cb(err);
if (!txp) return cb(new ClientError('Transaction proposal not found')); if (!txp) return cb(Errors.TX_NOT_FOUND);
return cb(null, txp); return cb(null, txp);
}); });
}; };
@ -1665,7 +1663,7 @@ WalletService.prototype.scan = function(opts, cb) {
self._runLocked(cb, function(cb) { self._runLocked(cb, function(cb) {
self.getWallet({}, function(err, wallet) { self.getWallet({}, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE);
wallet.scanStatus = 'running'; wallet.scanStatus = 'running';
self.storage.storeWallet(wallet, function(err) { self.storage.storeWallet(wallet, function(err) {
@ -1724,7 +1722,7 @@ WalletService.prototype.startScan = function(opts, cb) {
self.getWallet({}, function(err, wallet) { self.getWallet({}, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE);
setTimeout(function() { setTimeout(function() {
self.scan(opts, scanFinished); self.scan(opts, scanFinished);

12
test/integration/server.js

@ -1547,7 +1547,8 @@ describe('Wallet service', function() {
server.createAddress({}, function(err, address) { server.createAddress({}, function(err, address) {
should.not.exist(address); should.not.exist(address);
should.exist(err); should.exist(err);
err.message.should.contain('not complete'); err.code.should.equal('WALLET_NOT_COMPLETE');
err.message.should.equal('Wallet is not complete');
done(); done();
}); });
}); });
@ -1578,7 +1579,7 @@ describe('Wallet service', function() {
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {
should.not.exist(tx); should.not.exist(tx);
should.exist(err); should.exist(err);
err.message.should.contain('not complete'); err.code.should.equal('WALLET_NOT_COMPLETE');
done(); done();
}); });
}); });
@ -2906,7 +2907,8 @@ describe('Wallet service', function() {
}, function(err, txp) { }, function(err, txp) {
should.exist(err); should.exist(err);
should.not.exist(txp); should.not.exist(txp);
err.message.should.contain('not found'); err.code.should.equal('TX_NOT_FOUND')
err.message.should.equal('Transaction proposal not found');
done(); done();
}); });
}); });
@ -3178,7 +3180,7 @@ describe('Wallet service', function() {
should.not.exist(err); should.not.exist(err);
server.getWallet({}, function(err, w) { server.getWallet({}, function(err, w) {
should.exist(err); should.exist(err);
err.message.should.equal('Wallet not found'); err.code.should.equal('WALLET_NOT_FOUND');
should.not.exist(w); should.not.exist(w);
async.parallel([ async.parallel([
@ -3237,7 +3239,7 @@ describe('Wallet service', function() {
function(next) { function(next) {
server.getWallet({}, function(err, wallet) { server.getWallet({}, function(err, wallet) {
should.exist(err); should.exist(err);
err.message.should.contain('not found'); err.code.should.equal('WALLET_NOT_FOUND');
next(); next();
}); });
}, },

Loading…
Cancel
Save