diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index c60ae4b2946851844c40b5404da3ebcb742781c9..cef3bf7cf698ecc5b96f593da603decad886122d 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -12,7 +12,7 @@ from ..tools.exceptions import NoPeerAvailable import logging import inspect import hashlib -from requests.exceptions import ConnectTimeout +from requests.exceptions import RequestException, ConnectTimeout class Cache(): @@ -128,12 +128,12 @@ class Community(object): (next_peer.pubkey not in traversed_pubkeys))) if next_peer.pubkey not in traversed_pubkeys: self._peering_traversal(next_peer, found_peers, traversed_pubkeys) - except ConnectTimeout: - pass except TimeoutError: pass except ValueError: pass + except RequestException as e: + pass def peering(self): peers = [] @@ -218,7 +218,6 @@ class Community(object): self.peers.remove(peer) self.peers.append(peer) continue - raise NoPeerAvailable(self.currency, len(self.peers)) def post(self, request, req_args={}, post_args={}): diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index ac552f8acba2ce8a0d347e1d9f464c14eb460b8d..0bd4a8d951adef4b811ff10a7c6eed9e9ba5bb90 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -6,9 +6,10 @@ Created on 2 févr. 2014 import logging import time +import requests from ucoinpy.api import bma -from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication +from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QMessageBox from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal from PyQt5.QtGui import QIcon from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget @@ -47,6 +48,10 @@ class BlockchainWatcher(QObject): self.last_block = block_number except NoPeerAvailable: return + except requests.exceptions.RequestException as e: + QMessageBox.critical(self, ":(", + str(e), + QMessageBox.Ok) new_block_mined = pyqtSignal(int) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index 4bb208c999ebe14d5603e5919ca84b459d1a8e4a..4a8f05d5e075a1e17677f16b8d99f80b50ccbb9e 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -18,6 +18,7 @@ from ..tools.exceptions import NoPeerAvailable from ..__init__ import __version__ import logging +import requests class Loader(QObject): @@ -189,6 +190,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): str(e), QMessageBox.Ok) continue + except requests.exceptions.RequestException as e: + QMessageBox.critical(self, ":(", + str(e), + QMessageBox.Ok) self.menu_contacts_list.clear() for contact in self.app.current_account.contacts: diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index e3f75e115c2ed4fe3d9cd5f5fe14fb4e99e9d3c6..ac25c61b9901273a5ce742579c89124080e2c8e9 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -5,6 +5,8 @@ Created on 8 mars 2014 ''' import logging +import requests + from ucoinpy.api import bma from ucoinpy.api.bma import ConnectionHandler from ucoinpy.documents.peer import Peer @@ -65,6 +67,11 @@ class StepPageInit(Step): QMessageBox.critical(self.config_dialog, "Server Error", "Cannot join any peer in this community.") raise + except requests.exceptions.RequestException as e: + QMessageBox.critical(self, ":(", + str(e), + QMessageBox.Ok) + raise def display_page(self): self.config_dialog.button_previous.setEnabled(False) @@ -155,8 +162,12 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'], peer_data['signature'])) - self.community.peers.append(peer) - except: + if peer.currency == self.community.currency: + self.community.peers.append(peer) + else: + QMessageBox.critical(self, "Error", + "This peer doesn't use this community currency.") + except requests.exceptions.RequestException as e: QMessageBox.critical(self, "Server error", "Cannot get node peering") self.tree_peers.setModel(PeeringTreeModel(self.community)) @@ -187,6 +198,15 @@ Would you like to publish the key ?""".format(self.account.pubkey)) except ValueError as e: QMessageBox.critical(self, "Pubkey publishing error", e.message) + except NoPeerAvailable as e: + QMessageBox.critical(self, "Network error", + "Couldn't connect to network : {0}".format(e), + QMessageBox.Ok) + except Exception as e: + QMessageBox.critical(self, "Error", + "{0}".format(e), + QMessageBox.Ok) + else: return