From f97b86ef755c80453bab1a8eae9fddb57ba35a7d Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 14 Aug 2018 09:09:37 +0800 Subject: [PATCH] Exception handling in TxSearch --- html/js/controllers/account.js | 17 +++++++++++++++++ html/partials/account-overview.html | 3 +++ html/partials/account-transactions.html | 5 ++++- src/CurrentBlockchainStatus.cpp | 9 +++++---- src/TxSearch.cpp | 7 ++----- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/html/js/controllers/account.js b/html/js/controllers/account.js index a15c2d9..b51e4a6 100755 --- a/html/js/controllers/account.js +++ b/html/js/controllers/account.js @@ -49,6 +49,7 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q $scope.transactions = []; $scope.blockchain_height = 0; + $scope.error = ""; // var private_view_key = AccountService.getViewKey(); @@ -122,6 +123,14 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q var data = response.data; + if (data.status === "error") + { + $scope.error = "An error occured in fetchAddressInfo: " + + data.reason; + $scope.transactions = []; + return; + } + var promises = []; var view_only = AccountService.isViewOnly(); @@ -181,6 +190,14 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q var data = response.data; + if (data.status === "error") + { + $scope.error = "An error occured in fetchTransactions: " + + data.reason; + $scope.transactions = []; + return; + } + var scanned_block_timestamp = data.scanned_block_timestamp || 0; if (scanned_block_timestamp > 0) diff --git a/html/partials/account-overview.html b/html/partials/account-overview.html index cc7e073..4c71993 100755 --- a/html/partials/account-overview.html +++ b/html/partials/account-overview.html @@ -50,6 +50,9 @@
+
+

{{error}}

+
diff --git a/html/partials/account-transactions.html b/html/partials/account-transactions.html index 04659d6..cd3030c 100755 --- a/html/partials/account-transactions.html +++ b/html/partials/account-transactions.html @@ -39,8 +39,11 @@
+
+

{{error}}

+
<< Previous 20 Next 20 >> - \ No newline at end of file + diff --git a/src/CurrentBlockchainStatus.cpp b/src/CurrentBlockchainStatus.cpp index 5b0dd80..0a14576 100755 --- a/src/CurrentBlockchainStatus.cpp +++ b/src/CurrentBlockchainStatus.cpp @@ -48,10 +48,10 @@ CurrentBlockchainStatus::monitor_blockchain() OMINFO << "Current blockchain height: " << current_height << ", no of mempool txs: " << mempool_txs.size(); - clean_search_thread_map(); - check_search_threads_for_exceptions(); + clean_search_thread_map(); + std::this_thread::sleep_for( std::chrono::seconds( bc_setup.refresh_block_status_every_seconds)); @@ -980,9 +980,10 @@ CurrentBlockchainStatus::check_search_threads_for_exceptions() found_any_exception = true; std::rethrow_exception(eptr); } - catch (const std::exception& e) + catch (std::exception const& e) { - OMERROR << "Error in search thread: " << e.what(); + OMERROR << "Error in search thread: " << e.what() + << ". It will be cleared."; } } } diff --git a/src/TxSearch.cpp b/src/TxSearch.cpp index 1096526..832c4dc 100755 --- a/src/TxSearch.cpp +++ b/src/TxSearch.cpp @@ -289,8 +289,7 @@ TxSearch::operator()() if (tx_mysql_id == 0) { - throw TxSearchException("tx_mysql_id is zero!"); - //todo what should be done when insert_tx fails? + throw TxSearchException("tx_mysql_id is zero!"); } vector outputs_found; @@ -341,7 +340,6 @@ TxSearch::operator()() } // if (!found_mine_outputs.empty()) - // SECOND component: Checking for our key images, i.e., inputs. // no need mutex here, as this will be exectued only after @@ -499,8 +497,7 @@ TxSearch::operator()() // it already // exisits in the MySQL. So maybe can now // check if we have it and get tx_mysql_id this - // way. - //todo what should be done when insert_tx fails? + // way. } } // if (tx_mysql_id == 0)