Improve the error handling to expose and log errors if removing a card fails.

This commit is contained in:
Andy Phillipson 2016-11-21 15:10:59 -05:00
commit 1a2fea578d
4 changed files with 22 additions and 5 deletions

View file

@ -64,6 +64,8 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
if (err) { if (err) {
$log.error(err); $log.error(err);
$scope.error = gettextCatalog.getString('Could not get transactions'); $scope.error = gettextCatalog.getString('Could not get transactions');
self.bitpayCardTransactionHistory = null;
self.bitpayCardCurrentBalance = null;
return; return;
} }

View file

@ -11,7 +11,11 @@ angular.module('copayApp.controllers').controller('preferencesBitpayCardControll
}; };
var remove = function(card) { var remove = function(card) {
bitpayCardService.remove(card, function() { bitpayCardService.remove(card, function(err) {
if (err) {
$scope.error = gettextCatalog.getString('Could not remove card');
return;
}
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$timeout(function() { $timeout(function() {
$state.go('tabs.home'); $state.go('tabs.home');

View file

@ -33,7 +33,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
var _setError = function(msg, e) { var _setError = function(msg, e) {
$log.error(msg); $log.error(msg);
var error = e.data ? e.data.error : msg; var error = (e && e.data && e.data.error) ? e.data.error : msg;
return error; return error;
}; };
@ -175,7 +175,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
root.getBitpayDebitCards(function(err, data) { root.getBitpayDebitCards(function(err, data) {
if (err) return cb(err); if (err) return cb(err);
var card = lodash.find(data, {id : cardId}); var card = lodash.find(data, {id : cardId});
if (!card) return cb(_setError('Not card found')); if (!card) return cb(_setError('Card not found'));
// Get invoices // Get invoices
$http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) { $http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) {
$log.info('BitPay Get Invoices: SUCCESS'); $log.info('BitPay Get Invoices: SUCCESS');
@ -212,7 +212,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
root.getBitpayDebitCards(function(err, data) { root.getBitpayDebitCards(function(err, data) {
if (err) return cb(err); if (err) return cb(err);
var card = lodash.find(data, {id : cardId}); var card = lodash.find(data, {id : cardId});
if (!card) return cb(_setError('Not card found')); if (!card) return cb(_setError('Card not found'));
$http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) { $http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) {
$log.info('BitPay TopUp: SUCCESS'); $log.info('BitPay TopUp: SUCCESS');
if(data.data.error) { if(data.data.error) {
@ -290,8 +290,16 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
root.remove = function(card, cb) { root.remove = function(card, cb) {
storageService.removeBitpayDebitCard(BITPAY_CARD_NETWORK, card, function(err) { storageService.removeBitpayDebitCard(BITPAY_CARD_NETWORK, card, function(err) {
if (err) {
$log.error('Error removing BitPay debit card: ' + err);
// Continue, try to remove/cleanup card history
}
storageService.removeBitpayDebitCardHistory(BITPAY_CARD_NETWORK, card, function(err) { storageService.removeBitpayDebitCardHistory(BITPAY_CARD_NETWORK, card, function(err) {
$log.info('BitPay Debit Card(s) Removed: SUCCESS'); if (err) {
$log.error('Error removing BitPay debit card transaction history: ' + err);
return cb(err);
}
$log.info('Successfully removed BitPay debit card');
return cb(); return cb();
}); });
}); });

View file

@ -6,6 +6,9 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content> <ion-content>
<div ng-show="error" class="text-center m10t assertive">
{{error}}
</div>
<div class="list"> <div class="list">
<div class="item item-divider" translate> <div class="item item-divider" translate>
Cards Cards