Merge pull request #312 from isocolsky/improve_errors
Improve error messages
This commit is contained in:
commit
9b7b978d28
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue