From 03fe48209e6fb0ec639024f1ede2afd92e1cc421 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 5 Aug 2015 10:41:03 -0300 Subject: [PATCH 1/3] add WALLET_NOT_FOUND --- lib/errors/errordefinitions.js | 1 + lib/server.js | 6 +++--- test/integration/server.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 877be20..0ea050e 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -26,6 +26,7 @@ var errors = { WALLET_ALREADY_EXISTS: 'Wallet already exists', WALLET_FULL: 'Wallet full', WALLET_NOT_COMPLETE: 'Replace only works on complete wallets', + WALLET_NOT_FOUND: 'Wallet not found', }; var errorObjects = _.zipObject(_.map(errors, function(msg, code) { diff --git a/lib/server.js b/lib/server.js index 9f6da6f..dac6cff 100644 --- a/lib/server.js +++ b/lib/server.js @@ -253,7 +253,7 @@ WalletService.prototype.getWallet = function(opts, cb) { self.storage.fetchWallet(self.walletId, function(err, wallet) { 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); }); }; @@ -285,7 +285,7 @@ WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) { self.storage.fetchWallet(self.walletId, function(err, wallet) { 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); if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { return cb(new ClientError()); @@ -397,7 +397,7 @@ WalletService.prototype.joinWallet = function(opts, cb) { self.storage.fetchWallet(opts.walletId, function(err, wallet) { 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); if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { diff --git a/test/integration/server.js b/test/integration/server.js index 4b5e217..7af341e 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3178,7 +3178,7 @@ describe('Wallet service', function() { should.not.exist(err); server.getWallet({}, function(err, w) { should.exist(err); - err.message.should.equal('Wallet not found'); + err.code.should.equal('WALLET_NOT_FOUND'); should.not.exist(w); async.parallel([ @@ -3237,7 +3237,7 @@ describe('Wallet service', function() { function(next) { server.getWallet({}, function(err, wallet) { should.exist(err); - err.message.should.contain('not found'); + err.code.should.equal('WALLET_NOT_FOUND'); next(); }); }, From 76c545b1100aa6afe3278e4975b0b6d8ac3a698f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 5 Aug 2015 10:44:09 -0300 Subject: [PATCH 2/3] add WALLET_NOT_COMPLETE --- lib/errors/errordefinitions.js | 2 +- lib/server.js | 10 ++++------ test/integration/server.js | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 0ea050e..43b8ad3 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -25,7 +25,7 @@ var errors = { UPGRADE_NEEDED: 'Client app needs to be upgraded', WALLET_ALREADY_EXISTS: 'Wallet already exists', 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', }; diff --git a/lib/server.js b/lib/server.js index dac6cff..0fc2fe3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -544,8 +544,7 @@ WalletService.prototype.createAddress = function(opts, cb) { self._runLocked(cb, function(cb) { self.getWallet({}, function(err, wallet) { 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); var address = wallet.createAddress(false); @@ -977,8 +976,7 @@ WalletService.prototype.createTx = function(opts, cb) { self._runLocked(cb, function(cb) { self.getWallet({}, function(err, wallet) { 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); var copayer = wallet.getCopayer(self.copayerId); var hash; @@ -1665,7 +1663,7 @@ WalletService.prototype.scan = function(opts, cb) { self._runLocked(cb, function(cb) { self.getWallet({}, function(err, wallet) { 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'; self.storage.storeWallet(wallet, function(err) { @@ -1724,7 +1722,7 @@ WalletService.prototype.startScan = function(opts, cb) { self.getWallet({}, function(err, wallet) { 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() { self.scan(opts, scanFinished); diff --git a/test/integration/server.js b/test/integration/server.js index 7af341e..e348733 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1547,7 +1547,8 @@ describe('Wallet service', function() { server.createAddress({}, function(err, address) { should.not.exist(address); 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(); }); }); @@ -1578,7 +1579,7 @@ describe('Wallet service', function() { server.createTx(txOpts, function(err, tx) { should.not.exist(tx); should.exist(err); - err.message.should.contain('not complete'); + err.code.should.equal('WALLET_NOT_COMPLETE'); done(); }); }); From e4e138e139e04e3a5f11b1da9c6be4055cae9d0d Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 5 Aug 2015 10:48:36 -0300 Subject: [PATCH 3/3] add TX_NOT_FOUND --- lib/errors/errordefinitions.js | 1 + lib/server.js | 2 +- test/integration/server.js | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 43b8ad3..8a7bdbd 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -21,6 +21,7 @@ var errors = { TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time', TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime', 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', UPGRADE_NEEDED: 'Client app needs to be upgraded', WALLET_ALREADY_EXISTS: 'Wallet already exists', diff --git a/lib/server.js b/lib/server.js index 0fc2fe3..0bb93b4 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1085,7 +1085,7 @@ WalletService.prototype.getTx = function(opts, cb) { self.storage.fetchTx(self.walletId, opts.txProposalId, function(err, txp) { 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); }); }; diff --git a/test/integration/server.js b/test/integration/server.js index e348733..cb19bf0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2907,7 +2907,8 @@ describe('Wallet service', function() { }, function(err, txp) { should.exist(err); 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(); }); });