Browse Source

improve error messages

activeAddress
Ivan Socolsky 10 years ago
parent
commit
15798be382
  1. 15
      lib/server.js
  2. 4
      test/integration.js

15
lib/server.js

@ -496,25 +496,22 @@ CopayServer.prototype.removePendingTx = function(opts, cb) {
Utils.runLocked(self.walletId, cb, function(cb) { Utils.runLocked(self.walletId, cb, function(cb) {
self.storage.fetchTx(self.walletId, opts.id, function(err, txp) { self.getTx({
id: opts.id
}, 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.isPending()) if (!txp.isPending())
return cb(new ClientError('Transaction proposal not pending')); return cb(new ClientError('Transaction proposal not pending'));
if (txp.creatorId !== self.copayerId) if (txp.creatorId !== self.copayerId)
return cb(new ClientError('Not allowed to erase this TX')); return cb(new ClientError('Only creators can remove pending proposals'));
var actors = txp.getActors(); var actors = txp.getActors();
if (actors.length > 1) if (actors.length > 1 || (actors.length == 1 && actors[0] !== self.copayerId))
return cb(new ClientError('Not allowed to erase this TX')); return cb(new ClientError('Cannot remove a proposal signed/rejected by other copayers'));
if (actors.length == 1 && actors[0] !== self.copayerId)
return cb(new ClientError('Not allowed to erase this TX'));
self.storage.removeTx(self.walletId, opts.id, cb); self.storage.removeTx(self.walletId, opts.id, cb);
}); });

4
test/integration.js

@ -1310,7 +1310,7 @@ describe('Copay server', function() {
server2.removePendingTx({ server2.removePendingTx({
id: txp.id id: txp.id
}, function(err) { }, function(err) {
err.message.should.contain('Not allowed'); err.message.should.contain('creators');
server2.getPendingTxs({}, function(err, txs) { server2.getPendingTxs({}, function(err, txs) {
txs.length.should.equal(1); txs.length.should.equal(1);
done(); done();
@ -1330,7 +1330,7 @@ describe('Copay server', function() {
server.removePendingTx({ server.removePendingTx({
id: txp.id id: txp.id
}, function(err) { }, function(err) {
err.message.should.contain('Not allowed'); err.message.should.contain('other copayers');
done(); done();
}); });
}); });

Loading…
Cancel
Save