diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 877be20..8a7bdbd 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -21,11 +21,13 @@ 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', 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) { diff --git a/lib/server.js b/lib/server.js index 9f6da6f..0bb93b4 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)) { @@ -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; @@ -1087,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); }); }; @@ -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 4b5e217..cb19bf0 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(); }); }); @@ -2906,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(); }); }); @@ -3178,7 +3180,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 +3239,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(); }); },